diff --git a/lib/table_print/config.rb b/lib/table_print/config.rb index b9f385e..79e1068 100644 --- a/lib/table_print/config.rb +++ b/lib/table_print/config.rb @@ -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) diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 5a09932..b3550b4 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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