Class: Vorpal::ClassConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vorpal/configs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ ClassConfig

Returns a new instance of ClassConfig.



135
136
137
138
139
140
141
142
143
144
# File 'lib/vorpal/configs.rb', line 135

def initialize(attrs)
  @has_manys = []
  @belongs_tos = []
  @has_ones = []
  @local_association_configs = []

  attrs.each do |k,v|
    instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#belongs_tosObject

Returns the value of attribute belongs_tos.



133
134
135
# File 'lib/vorpal/configs.rb', line 133

def belongs_tos
  @belongs_tos
end

#db_classObject (readonly)

Returns the value of attribute db_class.



132
133
134
# File 'lib/vorpal/configs.rb', line 132

def db_class
  @db_class
end

#deserializerObject (readonly)

Returns the value of attribute deserializer.



132
133
134
# File 'lib/vorpal/configs.rb', line 132

def deserializer
  @deserializer
end

#domain_classObject (readonly)

Returns the value of attribute domain_class.



132
133
134
# File 'lib/vorpal/configs.rb', line 132

def domain_class
  @domain_class
end

#has_manysObject

Returns the value of attribute has_manys.



133
134
135
# File 'lib/vorpal/configs.rb', line 133

def has_manys
  @has_manys
end

#has_onesObject

Returns the value of attribute has_ones.



133
134
135
# File 'lib/vorpal/configs.rb', line 133

def has_ones
  @has_ones
end

#local_association_configsObject (readonly)

Returns the value of attribute local_association_configs.



132
133
134
# File 'lib/vorpal/configs.rb', line 132

def local_association_configs
  @local_association_configs
end

#serializerObject (readonly)

Returns the value of attribute serializer.



132
133
134
# File 'lib/vorpal/configs.rb', line 132

def serializer
  @serializer
end

Instance Method Details

#build_db_object(attributes) ⇒ Object



146
147
148
# File 'lib/vorpal/configs.rb', line 146

def build_db_object(attributes)
  db_class.new(attributes)
end

#deserialize(db_object) ⇒ Object



166
167
168
169
# File 'lib/vorpal/configs.rb', line 166

def deserialize(db_object)
  attributes = get_db_object_attributes(db_object)
  serialization_required? ? deserializer.deserialize(domain_class.new, attributes) : db_object
end

#get_attribute(db_object, attribute) ⇒ Object



175
176
177
# File 'lib/vorpal/configs.rb', line 175

def get_attribute(db_object, attribute)
  db_object.send(attribute)
end

#get_db_object_attributes(db_object) ⇒ Object



154
155
156
# File 'lib/vorpal/configs.rb', line 154

def get_db_object_attributes(db_object)
  symbolize_keys(db_object.attributes)
end

#serialization_required?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/vorpal/configs.rb', line 158

def serialization_required?
  domain_class.superclass.name != 'ActiveRecord::Base'
end

#serialize(object) ⇒ Object



162
163
164
# File 'lib/vorpal/configs.rb', line 162

def serialize(object)
  serializer.serialize(object)
end

#set_attribute(db_object, attribute, value) ⇒ Object



171
172
173
# File 'lib/vorpal/configs.rb', line 171

def set_attribute(db_object, attribute, value)
  db_object.send("#{attribute}=", value)
end

#set_db_object_attributes(db_object, attributes) ⇒ Object



150
151
152
# File 'lib/vorpal/configs.rb', line 150

def set_db_object_attributes(db_object, attributes)
  db_object.attributes = attributes
end