Module: Prestashop::Mapper::Extension::InstanceMethods
- Defined in:
- lib/prestashop/mapper/extension.rb
Instance Method Summary collapse
-
#create ⇒ Object
Create new model from instance, based on class resource a payload generated from hash method.
-
#hash_id(id) ⇒ Object
Generate hash with ID.
-
#hash_ids(ids) ⇒ Object
Make array of unique IDs in hash.
-
#payload ⇒ Object
Create payload for create new object, coverts hash to XML.
Instance Method Details
#create ⇒ Object
Create new model from instance, based on class resource a payload generated from hash method
Car.new(name: 'BMW 7', manufacturer: 'BMW').create # => { id: 1, name: 'BMW 7', manufacturer: 'BMW' }
149 150 151 152 |
# File 'lib/prestashop/mapper/extension.rb', line 149 def create result = Client.create self.class.resource, payload result ? result[self.class.model] : nil end |
#hash_id(id) ⇒ Object
Generate hash with ID
car.hash_id(1) # => {id: 1}
124 125 126 |
# File 'lib/prestashop/mapper/extension.rb', line 124 def hash_id id { id: id } if id end |
#hash_ids(ids) ⇒ Object
Make array of unique IDs in hash
car.hash_ids(1,2,3) # => [{id: 1},{id: 2},{id: 3}]
132 133 134 |
# File 'lib/prestashop/mapper/extension.rb', line 132 def hash_ids ids ids.flatten.uniq.map{|id| hash_id(id)} if ids end |
#payload ⇒ Object
Create payload for create new object, coverts hash to XML
car.payload # => '<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"><car><name><![CDATA[BMW 7]]></name><manufacturer><![CDATA[BMW]]></manufacturer></car></prestashop>'
140 141 142 |
# File 'lib/prestashop/mapper/extension.rb', line 140 def payload Api::Converter.build(self.class.resource, self.class.model, hash) end |