Sha256: 2321f3cd8bbcb7c104d9778479e70e9f9c83a21a211d7f6c84af1f8bc2e0e20b

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

module YamlRpc

  class <<self  
  
    # Helper method to decode passed arguments on the server side.
    #
    # Please note this is trivial task and you don't have to use this helper function to decode POST data on the server.
    # You can even use different language to parse YAML, like PHP.
    #
    # * <tt>params</tt> Hash
    # * <tt>fields</tt> If nil, will decode all passed params; otherwise only passed list of keys
    def decode(params, fields = nil)
      r = {}
      fields = params.keys unless fields
      fields = fields.is_a?(Array) ? fields : [ fields ]
      fields.each { |k| r[k] = YAML::load(params[k] || "--- \n" ) }
      r
    end
  
    # Helper method to decode arguments on the server side.
    # 
    # Returns a list of decoded values so you can use:
    #
    # image, description, keywords = YamlRpc.decode_to_ary(params, [:image, :description, :keywords])
    #
    # * <tt>params</tt> Hash
    # * <tt>fields</tt> Optional, single field name or array of field names, ie. [:foo, :bar]
    def decode_to_ary(params, fields)
      r = nil
      fields = fields.is_a?(Array) ? fields : [ fields ]
      r = fields.map { |k| YAML::load(params[k] || "--- \n") }
      r.size > 1 ? r : r.first
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
yamlrpc-0.1.080704174553 lib/yamlrpc/helpers.rb
yamlrpc-0.2.3 lib/yamlrpc/helpers.rb
yamlrpc-0.2.2 lib/yamlrpc/helpers.rb
yamlrpc-0.1.080701110311 lib/yamlrpc/helpers.rb
yamlrpc-0.1.080706215610 lib/yamlrpc/helpers.rb
yamlrpc-1.0.0 lib/yamlrpc/helpers.rb
yamlrpc-1.0.2 lib/yamlrpc/helpers.rb
yamlrpc-1.0.3 lib/yamlrpc/helpers.rb
yamlrpc-0.2.1 lib/yamlrpc/helpers.rb
yamlrpc-1.0.1 lib/yamlrpc/helpers.rb
yamlrpc-1.0.4 lib/yamlrpc/helpers.rb