Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve updating existing Rails config hash values

Closes #4, closes #7
  • Loading branch information...
commit 87a8eefd48f3e0456759cfad0acd8eb4f10c2d5e 1 parent ead4705
Mislav Marohnić authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/choices/rails.rb
9 lib/choices/rails.rb
View
@@ -1,3 +1,4 @@
+require 'hashie/mash'
require 'choices'
module Choices::Rails
@@ -23,7 +24,13 @@ def from_file(name)
settings.each do |key, value|
old_value = self.respond_to?(key) ? self.send(key) : nil
- if old_value && old_value.is_a?(Hash) && value.is_a?(Hash)
+ if "Rails::OrderedOptions" == old_value.class.name
+ # convert from Array to a real Hash
+ old_value = old_value.inject({}) {|h,(k,v)| h[k]=v; h }
+ end
+
+ if Hash === value and Hash === old_value
+ # don't overwrite existing Hash values; deep update them
value = Hashie::Mash.new(old_value).update value
end
Please sign in to comment.
Something went wrong with that request. Please try again.