class GlobalRegistryModels::Entity::Base
Public Class Methods
attributes_hash(attributes)
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 28 def self.attributes_hash(attributes) {'entity'.to_sym => { name => attributes }} end
default_field()
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 37 def self.default_field '*' end
global_registry_resource()
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 24 def self.global_registry_resource GlobalRegistry::Entity end
name()
click to toggle source
The name of the entity class. The entity name is required in the api responses and requests, hence the need for this class method.
# File lib/global_registry_models/entity/base.rb, line 33 def self.name to_s.gsub(/.*::/, '').underscore end
new(params = {})
click to toggle source
Calls superclass method
# File lib/global_registry_models/entity/base.rb, line 10 def initialize(params = {}) super(params) @relationships = [] params.each do |key,value| create_relationship(key,value) if key.to_s.include? ':relationship' end end
search_params()
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 18 def self.search_params { entity_type: name } end
specific_attributes_preparations(object, attributes)
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 45 def self.specific_attributes_preparations(object, attributes) object.relationships.each do |relationship| attributes["#{relationship.relationship_type}:relationship"] = { relationship.entity_type => relationship.related_entity_id, 'client_integration_id' => relationship.client_integration_id } end attributes end
Public Instance Methods
relationships()
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 41 def relationships @relationships end
Private Instance Methods
create_relationship(key,value_hash)
click to toggle source
# File lib/global_registry_models/entity/base.rb, line 57 def create_relationship(key,value_hash) @relationships << Relationship.new(relationship_type: key.to_s.split(':').first, entity_type: value_hash.keys.first, related_entity_id: value_hash.values.first, client_integration_id: value_hash['client_integration_id']) end