Skip to content

Commit

Permalink
Return integer values instead of FigNewton::Node
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Jackson committed Nov 13, 2012
1 parent 269a4f0 commit 3510023
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/yaml/test_config.yml
Expand Up @@ -8,3 +8,5 @@ first:
second: second:
third: foo third: foo
fourth: bar fourth: bar

port: 1234
4 changes: 4 additions & 0 deletions features/fig_newton.feature
Expand Up @@ -34,3 +34,7 @@ Feature: Functionality of the fig_newton gem
When I ask for the value for "base_url" When I ask for the value for "base_url"
Then I should see "http://cheezyworld.com" Then I should see "http://cheezyworld.com"


Scenario: Requesting a numerical value
Given I have read the configuration file
When I ask for the value for "port"
Then I should see 1234
4 changes: 4 additions & 0 deletions features/step_definitions/fig_newton_steps.rb
Expand Up @@ -15,6 +15,10 @@
@value.should == value @value.should == value
end end


Then /^I should see (\d+)$/ do |value|
@value.should == value.to_i
end

When /^I ask for a value that does not exist named "([^\"]*)"$/ do |non_existing| When /^I ask for a value that does not exist named "([^\"]*)"$/ do |non_existing|
@does_not_exist = non_existing @does_not_exist = non_existing
end end
Expand Down
7 changes: 6 additions & 1 deletion lib/fig_newton/missing.rb
Expand Up @@ -5,13 +5,18 @@ def method_missing(*args, &block)
m = args.first m = args.first
value = @yml[m.to_s] value = @yml[m.to_s]
super unless value super unless value
value = FigNewton::Node.new(value) unless value.kind_of? String value = FigNewton::Node.new(value) unless type_known? value
value value
end end


def read_file def read_file
@yml = YAML.load_file "#{yml_directory}/#{ENV['FIG_NEWTON_FILE']}" if ENV['FIG_NEWTON_FILE'] @yml = YAML.load_file "#{yml_directory}/#{ENV['FIG_NEWTON_FILE']}" if ENV['FIG_NEWTON_FILE']
FigNewton.load('default.yml') unless ENV['FIG_NEWTON_FILE'] FigNewton.load('default.yml') unless ENV['FIG_NEWTON_FILE']
end end

private
def type_known?(value)
value.kind_of? String or value.kind_of? Integer
end
end end
end end

0 comments on commit 3510023

Please sign in to comment.