Sha256: b34b7f422c88ae49ac6d4ba78938ec0eaaf4943953d5962912e5d12464fe5f1a
Contents?: true
Size: 815 Bytes
Versions: 1
Compression:
Stored size: 815 Bytes
Contents
module AqumulateAPI class Entity ATTR_MAP = {} SOURCE_ASSOCIATIONS = [] def initialize(attributes = {}) attributes.each { |k, v| instance_variable_set("@#{k}", v) } end def self.from_source(source) entity = new({}) self::ATTR_MAP.invert.each do |k, v| entity.send("#{v.to_s}=", source[k]) end self::SOURCE_ASSOCIATIONS.each do |association| next if source[association[:key]].nil? || source[association[:key]].empty? association_set = entity.send(association[:attr]) source[association[:key]].each do |association_source| association_set << association[:class].from_source(association_source) end entity.send("#{association[:attr].to_s}=", association_set) end entity end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aqumulate_api-0.2.0 | lib/aqumulate_api/entity.rb |