Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/zedkit/ext/hash.rb

Overview

We want to transform something like this:

{ :user => { :email => "[email protected]", :password => "pwd", :first_name => "Fred", :surname => "Flintstone" } }

Into something like this for submission to the ZedAPI:

{ 
  "user[email]" => "[email protected]",
  "user[password]" => "pwd", "user[first_name]" => "Fred", "user[surname]" => "Flintstone"
}

The API only ever uses a single level, never something like [user][name]. If more than a single level is submitted we don’t bother to try and sort it out here, as it will not work anyway. Let the caller figure that out and resolve it on their end.

FYI, the API’s backend controllers do NOT use mass assignment for attributes submitted, EVER. Submitting anything other than documented object data items for each API method has no negative impact. Inapplicable attributes, or nefarious submissions on update, such as user, are simply ignored.

Direct Known Subclasses

Zedkit::Instance

Instance Method Summary collapse

Instance Method Details

#flatten_zedkit_params!Object

The implementation of this did not require a staging hash until



38
39
40
41
42
43
44
45
46
47
# File 'lib/zedkit/ext/hash.rb', line 38

def flatten_zedkit_params!                      ## The implementation of this did not require a staging hash until
  tmph = {}                                     ## 1.9.2: RuntimeError: can't add a new key into hash during iteration
  each do |k,v|
    if v.is_a?(Hash)                                          # self.each do |k,v|
      v.each {|vk,vv| tmph["#{k}[#{vk}]"] = vv }              #   if v.is_a?(Hash)
      delete(k)                                               #     v.each {|vk,vv| merge!({ "#{k}[#{vk}]" => vv }) }
    end                                                       #     self.delete(k)
  end                                                         #   end
  merge!(tmph)                                                # end
end

#has_zedkit_errors?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/zedkit/ext/hash.rb', line 55

def has_zedkit_errors?
  has_key?("status") && self["status"]["result"] == "ERROR"
end

#zdelete_keys!(zedkeys = []) ⇒ Object



48
49
50
# File 'lib/zedkit/ext/hash.rb', line 48

def zdelete_keys!(zedkeys = [])
  delete_if {|k| zedkeys.include?(k.to_s) }
end

#zedkit_object?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/zedkit/ext/hash.rb', line 52

def zedkit_object?
  self.has_key?('uuid') && self['uuid'].is_a?(String) && self['uuid'].length == 32
end