Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Pelusa::Configuration#[] (WIP)
  • Loading branch information
solnic committed Feb 15, 2012
1 parent 48fd112 commit 856c7de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/pelusa/configuration.rb
Expand Up @@ -14,6 +14,11 @@ def initialize(yaml_path = YAML_PATH)
@_configuration = YAML.load_file(yaml_path).freeze
end

# @api public
def [](name)
for_lint(name)
end

# @api public
def sources
@_configuration['sources']
Expand All @@ -24,11 +29,16 @@ def enabled_lints
(Lint.all - disabled_lints).uniq
end

# @api public
def for_lint(name)
lints.fetch(name, {})
end

private

# @api private
def lints
@_configuration.fetch('lints', [])
@_configuration.fetch('lints', {})
end

# @api private
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/sample_config_one.yml
Expand Up @@ -4,3 +4,4 @@ lints:
enabled: false
LineRestriction:
enabled: true
limit: 80
12 changes: 12 additions & 0 deletions test/pelusa/configuration_test.rb
Expand Up @@ -19,5 +19,17 @@ module Pelusa
configuration.enabled_lints.must_equal(enabled_lints)
end
end

describe '#[]' do
let(:lint_configuration) { configuration['LineRestriction'] }

it 'returns a configuration hash for the given lint' do
lint_configuration.must_be_instance_of(Hash)
end

it 'must return valid configuration' do
lint_configuration['limit'].must_equal(80)
end
end
end
end

0 comments on commit 856c7de

Please sign in to comment.