Class: Rod::Rest::Proxy
- Inherits:
-
Object
- Object
- Rod::Rest::Proxy
- Defined in:
- lib/rod/rest/proxy.rb
Instance Method Summary collapse
-
#initialize(metadata, client, options = {}) ⇒ Proxy
constructor
Initialize new Proxy factory based on the
metadata
and associated with theclient
, used to fetch the descriptions of the objects. -
#new(hash) ⇒ Object
Return new instance of a proxy object based on the
hash
data.
Constructor Details
#initialize(metadata, client, options = {}) ⇒ Proxy
Initialize new Proxy factory based on the metadata
and associated with the client
, used to fetch the descriptions of the objects. Options:
-
collection_proxy_factory - factory used to create collection proxies for plural associations
11 12 13 14 15 16 17 |
# File 'lib/rod/rest/proxy.rb', line 11 def initialize(,client,={}) @metadata = @client = client @type = @metadata.name @collection_proxy_factory = [:collection_proxy_factory] || CollectionProxy @klass = build_class(@metadata) end |
Instance Method Details
#new(hash) ⇒ Object
Return new instance of a proxy object based on the hash
data.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rod/rest/proxy.rb', line 20 def new(hash) check_id(hash) proxy = @klass.new(hash[:rod_id],@type,@client,@collection_proxy_factory) @metadata.fields.each do |field| check_field(hash,field) proxy.instance_variable_set("@#{field.symbolic_name}",hash[field.symbolic_name]) end @metadata.singular_associations.each do |association| check_association(hash,association) proxy.instance_variable_set(association_variable_name(association),hash[association.symbolic_name]) end @metadata.plural_associations.each do |association| check_association(hash,association) proxy.instance_variable_set(count_variable_name(association),hash[association.symbolic_name][:count]) end proxy end |