Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Array#flatten on an array containing a Settingslogic object... #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source "http://rubygems.org"
group :development do group :development do
gem 'rake' gem 'rake'
gem 'jeweler' gem 'jeweler'
gem 'rspec', :require => 'spec' gem 'rspec'
gem 'rcov' gem 'rcov'
if RUBY_VERSION < "1.9" if RUBY_VERSION < "1.9"
gem 'ruby-debug' gem 'ruby-debug'
Expand Down
39 changes: 22 additions & 17 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
@@ -1,31 +1,36 @@
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
archive-tar-minitar (0.5.2)
columnize (0.3.6) columnize (0.3.6)
diff-lcs (1.1.3) diff-lcs (1.1.3)
git (1.2.5) git (1.2.5)
jeweler (1.6.4) jeweler (1.6.4)
bundler (~> 1.0) bundler (~> 1.0)
git (>= 1.2.5) git (>= 1.2.5)
rake rake
linecache (0.46) linecache19 (0.5.12)
rbx-require-relative (> 0.0.4) ruby_core_source (>= 0.1.4)
rake (0.9.2.2) rake (0.9.2.2)
rbx-require-relative (0.0.5)
rcov (0.9.11) rcov (0.9.11)
rspec (2.8.0) rspec (2.11.0)
rspec-core (~> 2.8.0) rspec-core (~> 2.11.0)
rspec-expectations (~> 2.8.0) rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.8.0) rspec-mocks (~> 2.11.0)
rspec-core (2.8.0) rspec-core (2.11.1)
rspec-expectations (2.8.0) rspec-expectations (2.11.2)
diff-lcs (~> 1.1.2) diff-lcs (~> 1.1.3)
rspec-mocks (2.8.0) rspec-mocks (2.11.2)
ruby-debug (0.10.4) ruby-debug-base19 (0.11.25)
columnize (>= 0.1) columnize (>= 0.3.1)
ruby-debug-base (~> 0.10.4.0) linecache19 (>= 0.5.11)
ruby-debug-base (0.10.4) ruby_core_source (>= 0.1.4)
linecache (>= 0.3) ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)


PLATFORMS PLATFORMS
ruby ruby
Expand All @@ -35,4 +40,4 @@ DEPENDENCIES
rake rake
rcov rcov
rspec rspec
ruby-debug ruby-debug19
7 changes: 4 additions & 3 deletions lib/settingslogic.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ def load!
instance instance
true true
end end

def reload! def reload!
@instance = nil @instance = nil
load! load!
end end

private private
def instance def instance
return @instance if @instance return @instance if @instance
@instance = new @instance = new
create_accessors! create_accessors!
@instance @instance
end end

def method_missing(name, *args, &block) def method_missing(name, *args, &block)
instance.send(name, *args, &block) instance.send(name, *args, &block)
end end
Expand Down Expand Up @@ -124,6 +124,7 @@ def initialize(hash_or_file = self.class.source, section = nil)
# Called for dynamically-defined keys, and also the first key deferenced at the top-level, if load! is not used. # Called for dynamically-defined keys, and also the first key deferenced at the top-level, if load! is not used.
# Otherwise, create_accessors! (called by new) will have created actual methods for each key. # Otherwise, create_accessors! (called by new) will have created actual methods for each key.
def method_missing(name, *args, &block) def method_missing(name, *args, &block)
super if name === :to_ary # delegate to_ary to Hash
key = name.to_s key = name.to_s
return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? key return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? key
value = fetch(key) value = fetch(key)
Expand Down
19 changes: 14 additions & 5 deletions spec/settingslogic_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
it "should access settings" do it "should access settings" do
Settings.setting2.should == 5 Settings.setting2.should == 5
end end

it "should access nested settings" do it "should access nested settings" do
Settings.setting1.setting1_child.should == "saweet" Settings.setting1.setting1_child.should == "saweet"
end end

it "should access deep nested settings" do it "should access deep nested settings" do
Settings.setting1.deep.another.should == "my value" Settings.setting1.deep.another.should == "my value"
end end
Expand All @@ -35,7 +35,7 @@
Settings.language.haskell.paradigm.should == 'functional' Settings.language.haskell.paradigm.should == 'functional'
Settings.language.smalltalk.paradigm.should == 'object oriented' Settings.language.smalltalk.paradigm.should == 'object oriented'
end end

it "should not collide with global methods" do it "should not collide with global methods" do
Settings3.nested.collides.does.should == 'not either' Settings3.nested.collides.does.should == 'not either'
Settings3[:nested] = 'fooey' Settings3[:nested] = 'fooey'
Expand Down Expand Up @@ -73,7 +73,7 @@
end end
e.should_not be_nil e.should_not be_nil
e.message.should =~ /Missing setting 'erlang' in 'language' section/ e.message.should =~ /Missing setting 'erlang' in 'language' section/

Settings.language['erlang'].should be_nil Settings.language['erlang'].should be_nil
Settings.language['erlang'] = 5 Settings.language['erlang'] = 5
Settings.language['erlang'].should == 5 Settings.language['erlang'].should == 5
Expand Down Expand Up @@ -158,5 +158,14 @@ class NoSource < Settingslogic; end
it "should be a hash" do it "should be a hash" do
Settings.send(:instance).should be_is_a(Hash) Settings.send(:instance).should be_is_a(Hash)
end end


# rspec-core issue 620
it "should not blow up if #to_ary is called on it via Array#flatten" do
lambda {
[ Settings, ['a'] ].flatten
}.should_not raise_error

[Settings, ['a']].flatten.should == [Settings, 'a']
end

end end