Skip to content

Commit

Permalink
allow configs to be loaded from remote sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Feb 24, 2015
1 parent 7746b98 commit fe4cdbf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maximus

[![Gem Version](https://badge.fury.io/rb/maximus.svg)](http://badge.fury.io/rb/maximus) [![Code Climate](https://codeclimate.com/github/wearefine/maximus/badges/gpa.svg)](https://codeclimate.com/github/wearefine/maximus) [![Build Status](https://travis-ci.org/wearefine/maximus.svg)](https://travis-ci.org/wearefine/maximus) [![Coverage Status](https://coveralls.io/repos/wearefine/maximus/badge.svg)](https://coveralls.io/r/wearefine/maximus) [![Inline docs](http://inch-ci.org/github/wearefine/maximus.svg?branch=master&style=flat)](http://inch-ci.org/github/wearefine/maximus)
[![Gem Version](https://badge.fury.io/rb/maximus.svg)](http://badge.fury.io/rb/maximus) [![Code Climate](https://codeclimate.com/github/wearefine/maximus/badges/gpa.svg)](https://codeclimate.com/github/wearefine/maximus) [![Build Status](https://travis-ci.org/wearefine/maximus.svg)](https://travis-ci.org/wearefine/maximus) [![Coverage Status](https://coveralls.io/repos/wearefine/maximus/badge.svg)](https://coveralls.io/r/wearefine/maximus) [![Inline docs](http://inch-ci.org/github/wearefine/maximus.svg?branch=master&style=flat)](http://inch-ci.org/github/wearefine/maximus) [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/maximus)

The all-in-one linting solution.

Expand Down Expand Up @@ -143,6 +143,10 @@ If calling Maximus::Wraith from a script, please see the note in lib/statistics/

### 0.1.6

Features:

* Remote config files can be specified

Bugfixes:

* Clean up config option loading/overriding
Expand Down
16 changes: 13 additions & 3 deletions lib/maximus/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_support'
require 'active_support/core_ext/hash/keys'
require 'open-uri'

module Maximus

Expand Down Expand Up @@ -210,12 +211,21 @@ def set_families(head_of_house, family)
# the reset of the process doesn't break
def load_config(value)
return value unless value.is_a?(String)
if File.exist?(value)
return YAML.load_file(value)

if value =~ /^http/
begin open(value)
YAML.load open(value).read
rescue
puts "#{value} not accessible"
{}
end
elsif File.exist?(value)
YAML.load_file(value)
else
puts "#{value} not found"
return {}
{}
end

end

# Create a temp file with config data
Expand Down
1 change: 1 addition & 0 deletions maximus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "thor"

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "pry-byebug", "~> 3.0"
spec.add_development_dependency "yard", "~> 0.8"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "coveralls", "~> 0.7.8"
Expand Down
25 changes: 22 additions & 3 deletions spec/maximus/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,29 @@
describe '#load_config', :isolated_environment do

context 'a file path is provided' do
let(:config_body) { 'rubocop: spec/support/rubocop.yml' }
it 'should load the file' do
expect( YAML.load_file(config.settings[:rubocop])['Rubolinter'] ).to be true

context 'at a local address' do
let(:config_body) { 'rubocop: spec/support/rubocop.yml' }
it 'should load the file' do
expect( YAML.load_file(config.settings[:rubocop])['Rubolinter'] ).to be true
end
end

context 'at an available remote address' do
let(:config_body) { 'rubocop: "https://raw.githubusercontent.com/wearefine/standards/master/linters/.rubocop.yml" ' }
it 'should load the file' do
expect( YAML.load_file(config.settings[:rubocop]) ).to be_a(Hash)
end
end

context 'at an unavailable remote address' do
let(:config_body) { 'rubocop: "http://raw.githubusercontent.com/wearefine/standards/master/linters/nonexistent_file.yml" ' }
it 'should report an error and return an empty hash' do
STDOUT.should_receive(:puts).with('http://raw.githubusercontent.com/wearefine/standards/master/linters/nonexistent_file.yml not accessible')
expect( YAML.load_file(config.settings[:rubocop]) ).to eq({})
end
end

end

context 'settings are provided' do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'maximus'
require 'coveralls'
require 'pry'
Coveralls.wear!

RSpec.configure do |config|
Expand Down

0 comments on commit fe4cdbf

Please sign in to comment.