Sha256: e9ad04d588ac45a16d70801b5d38341eb525238e01a3093dabd0af14d25aa842

Contents?: true

Size: 926 Bytes

Versions: 41

Compression:

Stored size: 926 Bytes

Contents

class Hash

  #this method adds an key/value pair in the pattern of :<name> => [] to the hash
  #only if the key <name> doesn't already exists. this function is provided
  #due to  http post's lack of providing the checkboxes field when no cb is
  #selected. I'm pretty sure that this could be moved direcly into the model
  #or even ActiveRecord.
  def add_key_for_checkboxes name
    self[name.to_s] = [] if self.stringify_keys[name.to_s].nil?
  end
  
  def stringify
    inject({}) do |options, (key, value)|
      if value.is_a?(Hash) || value.is_a?(Array)
        options[key.to_s] = value.stringify
      else
        options[key.to_s] = value.to_s
      end
      options
    end
  end
  
  def stringify!
    each do |key, value|
      delete(key)
      if value.is_a?(Hash) || value.is_a?(Array)
        store(key.to_s, value.stringify!)
      else
        store(key.to_s, value.to_s)
      end
    end
  end
  
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
alchemy_cms-2.1.12 lib/extensions/hash.rb
alchemy_cms-2.0.7 lib/extensions/hash.rb
alchemy_cms-2.1.11 lib/extensions/hash.rb
alchemy_cms-2.1.9.1 lib/extensions/hash.rb
alchemy_cms-2.1.9 lib/extensions/hash.rb
alchemy_cms-2.1.8.1 lib/extensions/hash.rb
alchemy_cms-2.1.8 lib/extensions/hash.rb
alchemy_cms-2.1.7 lib/extensions/hash.rb
alchemy_cms-2.1.6 lib/extensions/hash.rb
alchemy_cms-2.1.5 lib/extensions/hash.rb
alchemy_cms-2.1.4 lib/extensions/hash.rb
alchemy_cms-2.1.3 lib/extensions/hash.rb
alchemy_cms-2.1.2 lib/extensions/hash.rb
alchemy_cms-2.1.1 lib/extensions/hash.rb
alchemy_cms-2.1 lib/extensions/hash.rb
alchemy_cms-2.1.rc6 lib/extensions/hash.rb
alchemy_cms-2.1.rc5 lib/extensions/hash.rb
alchemy_cms-2.1.rc4 lib/extensions/hash.rb
alchemy_cms-2.1.rc3 lib/extensions/hash.rb
alchemy_cms-2.1.rc2 lib/extensions/hash.rb