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 Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source "http://rubygems.org"
group :development do
gem 'rake'
gem 'jeweler'
gem 'rspec', :require => 'spec'
gem 'rspec'
gem 'rcov'
if RUBY_VERSION < "1.9"
gem 'ruby-debug'
Expand Down
39 changes: 22 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
GEM
remote: http://rubygems.org/
specs:
archive-tar-minitar (0.5.2)
columnize (0.3.6)
diff-lcs (1.1.3)
git (1.2.5)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
linecache (0.46)
rbx-require-relative (> 0.0.4)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rcov (0.9.11)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.2)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.2)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
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
ruby
Expand All @@ -35,4 +40,4 @@ DEPENDENCIES
rake
rcov
rspec
ruby-debug
ruby-debug19
7 changes: 4 additions & 3 deletions lib/settingslogic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ def load!
instance
true
end

def reload!
@instance = nil
load!
end

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

def method_missing(name, *args, &block)
instance.send(name, *args, &block)
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.
# Otherwise, create_accessors! (called by new) will have created actual methods for each key.
def method_missing(name, *args, &block)
super if name === :to_ary # delegate to_ary to Hash
key = name.to_s
return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? key
value = fetch(key)
Expand Down
19 changes: 14 additions & 5 deletions spec/settingslogic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
it "should access settings" do
Settings.setting2.should == 5
end

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

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

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

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