class ActiveResource::Base
Public Instance Methods
find_object(name, type, key)
click to toggle source
Nested object finder by type uuid + object uuid.
MS data model have arrays which contains objects where each object have a special “type” uuid and object uuid. Type + Object uuids are PK for the object.
@attr name [Symbol] attribute name @attr type [String] “type” uuid @attr key [String] “object” uuid
# File lib/moy_sklad/client/resource.rb, line 15 def find_object(name, type, key) return nil if self.send(name).is_a?(MoySklad::Client::Attribute::MissingAttr) create_nested_resource(name) # Convert single attr to array self.send("#{name}=", [self.send(name)]) unless self.send(name).is_a?(Array) self.send(name).each do |v| return v if v.send(type) == key end nil end
Private Instance Methods
create_and_load_resource(name, attributes = nil)
click to toggle source
Construct nested resource class and load with given attributes NB: ALL nested classes should be created through this way.
# File lib/moy_sklad/client/resource.rb, line 34 def create_and_load_resource(name, attributes = nil) res = find_or_create_resource_for(name).new res.load(attributes) if !attributes.nil? res end
create_nested_collection(name)
click to toggle source
# File lib/moy_sklad/client/resource.rb, line 40 def create_nested_collection(name) create_nested_collection_or_resource(name) end
create_nested_collection_or_resource(name, collection = true)
click to toggle source
# File lib/moy_sklad/client/resource.rb, line 48 def create_nested_collection_or_resource(name, collection = true) name = name.to_s if !known_attributes.include?(name) || attributes[name].nil? known_attributes << name attributes[name] = collection ? [] : create_and_load_resource(name) end end
create_nested_resource(name)
click to toggle source
# File lib/moy_sklad/client/resource.rb, line 44 def create_nested_resource(name) create_nested_collection_or_resource(name, false) end