Sha256: f1031ce11a0b9732fed21ae4f13f2a0a17345ac2a6a933e09fdf98a455f566a3
Contents?: true
Size: 1.59 KB
Versions: 18
Compression:
Stored size: 1.59 KB
Contents
# Base Magento model handles basic crud operations and stores connection to magento instance. # It has the following class attributes: # # * <tt>connection</tt>: the Magento::Connection to use # # And the following instance attributes: # * <tt>attributes</tt>: the attributes of the magento object # module Magento class Base attr_accessor :attributes class << self; attr_accessor :connection end module ClassMethods # Uses the classes name and method to make an rpc call through connection def commit(method, *args) # TODO: need to catch errors sent back from magento and bubble them up appropriately method = "#{to_s.split('::').last.underscore.downcase}.#{method}" Magento::Base.connection.call(method, *args) end end module InstanceMethods def initialize(attributes = {}) @attributes = attributes.dup end # TODO: find out if the id naming is consistent def id @attributes["#{self.class.to_s.split('::').last.underscore.downcase}_id"] end def id=(_id) @attributes["#{self.class.to_s.split('::').last.underscore.downcase}_id"] = _id end def object_attributes=(new_attributes) return if new_attributes.nil? attributes = new_attributes.dup attributes.stringify_keys! attributes.each do |k, v| send(k + "=", v) end end def method_missing(method, *args) return nil unless @attributes @attributes[method.to_s] end end include InstanceMethods extend ClassMethods end end
Version data entries
18 entries across 18 versions & 1 rubygems