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

Exceptions are thrown when trying to acces nested property while suppress_errors is enabled. #47

Open
wants to merge 2 commits 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
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ If your default settings seem to be overwriting your environment-specific settin
>> Settings.cool.saweet
=> "nested settings"

>> Settings.get('cool.saweet')
=> "nested settings"

>> Settings.neat_setting
=> 800

Expand Down
4 changes: 4 additions & 0 deletions lib/settingslogic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def get(key)
curs = curs.send(p)
end
curs
rescue
return nil if suppress_errors

raise
end

def source(value = nil)
Expand Down
12 changes: 12 additions & 0 deletions spec/settingslogic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ class NoSource < Settingslogic; end
Settings4.non_existent_key.should be_nil
end


context "#get" do
it "should suppress errors for nonexistent nested parameters" do
expect { Settings4.get('non.existent.key') }.not_to raise_exception
end

it "should throw an exception for nonexistent nested parameters when suppress_errors=false" do
expect { Settings.get('non.existent.key') }.to raise_exception
end
end


# This one edge case currently does not pass, because it requires very
# esoteric code in order to make it pass. It was judged not worth fixing,
# as it introduces significant complexity for minor gain.
Expand Down