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

dup the klass config on retrieval so it does not clear between calls #77

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
9 changes: 8 additions & 1 deletion lib/table_print/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ def self.set(klass, val)
end

def self.for(klass)
@@klasses.fetch(klass) {}
config = @@klasses.fetch(klass) {}
if config.is_a?(Array)
config.map { |c| c.is_a?(Hash) ? c.dup : c }
elsif config.is_a?(Hash)
config.dup
else
config
end
end

def self.clear(klass)
Expand Down
6 changes: 6 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
TablePrint::Config.set(Sandbox::Blog, [:title, :author])
TablePrint::Config.for(Sandbox::Blog).should == [:title, :author]
end

it "makes a copy on retrieval" do |variable|
TablePrint::Config.set(Sandbox::Blog, [:title, :author])
TablePrint::Config.for(Sandbox::Blog).clear
TablePrint::Config.for(Sandbox::Blog).should == [:title, :author]
end
end

describe "clearing" do
Expand Down