class Vorpal::Config::ClassConfig

@private

Constants

ALLOWED_PRIMARY_KEY_TYPE_OPTIONS

Attributes

belongs_tos[RW]
db_class[R]
deserializer[R]
domain_class[R]
has_manys[RW]
has_ones[RW]
local_association_configs[R]
primary_key_type[R]
serializer[R]

Public Class Methods

new(attrs) click to toggle source
# File lib/vorpal/config/class_config.rb, line 13
def initialize(attrs)
  @has_manys = []
  @belongs_tos = []
  @has_ones = []
  @local_association_configs = []

  @serializer = attrs[:serializer]
  @deserializer = attrs[:deserializer]
  @domain_class = attrs[:domain_class]
  @db_class = attrs[:db_class]
  @primary_key_type = attrs[:primary_key_type]
  raise "Invalid primary_key_type: '#{@primary_key_type}'" unless ALLOWED_PRIMARY_KEY_TYPE_OPTIONS.include?(@primary_key_type)
end

Public Instance Methods

build_db_object(attributes) click to toggle source
# File lib/vorpal/config/class_config.rb, line 27
def build_db_object(attributes)
  db_class.new(attributes)
end
deserialize(db_object) click to toggle source
# File lib/vorpal/config/class_config.rb, line 47
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) click to toggle source
# File lib/vorpal/config/class_config.rb, line 56
def get_attribute(db_object, attribute)
  db_object.send(attribute)
end
get_db_object_attributes(db_object) click to toggle source
# File lib/vorpal/config/class_config.rb, line 35
def get_db_object_attributes(db_object)
  symbolize_keys(db_object.attributes)
end
serialization_required?() click to toggle source
# File lib/vorpal/config/class_config.rb, line 39
def serialization_required?
  domain_class.superclass.name != 'ActiveRecord::Base'
end
serialize(object) click to toggle source
# File lib/vorpal/config/class_config.rb, line 43
def serialize(object)
  serializer.serialize(object)
end
set_attribute(db_object, attribute, value) click to toggle source
# File lib/vorpal/config/class_config.rb, line 52
def set_attribute(db_object, attribute, value)
  db_object.send("#{attribute}=", value)
end
set_db_object_attributes(db_object, attributes) click to toggle source
# File lib/vorpal/config/class_config.rb, line 31
def set_db_object_attributes(db_object, attributes)
  db_object.attributes = attributes
end

Private Instance Methods

symbolize_keys(hash) click to toggle source
# File lib/vorpal/config/class_config.rb, line 62
def symbolize_keys(hash)
  result = {}
  hash.each_key do |key|
    result[key.to_sym] = hash[key]
  end
  result
end