Class: Vorpal::Config::ClassConfig
- Inherits:
-
Object
- Object
- Vorpal::Config::ClassConfig
- Defined in:
- lib/vorpal/config/class_config.rb
Constant Summary collapse
- ALLOWED_PRIMARY_KEY_TYPE_OPTIONS =
[:serial, :uuid]
Instance Attribute Summary collapse
-
#belongs_tos ⇒ Object
Returns the value of attribute belongs_tos.
-
#db_class ⇒ Object
readonly
Returns the value of attribute db_class.
-
#deserializer ⇒ Object
readonly
Returns the value of attribute deserializer.
-
#domain_class ⇒ Object
readonly
Returns the value of attribute domain_class.
-
#has_manys ⇒ Object
Returns the value of attribute has_manys.
-
#has_ones ⇒ Object
Returns the value of attribute has_ones.
-
#local_association_configs ⇒ Object
readonly
Returns the value of attribute local_association_configs.
-
#primary_key_type ⇒ Object
readonly
Returns the value of attribute primary_key_type.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
- #build_db_object(attributes) ⇒ Object
- #deserialize(db_object) ⇒ Object
- #get_attribute(db_object, attribute) ⇒ Object
- #get_db_object_attributes(db_object) ⇒ Object
-
#initialize(attrs) ⇒ ClassConfig
constructor
A new instance of ClassConfig.
- #serialization_required? ⇒ Boolean
- #serialize(object) ⇒ Object
- #set_attribute(db_object, attribute, value) ⇒ Object
- #set_db_object_attributes(db_object, attributes) ⇒ Object
Constructor Details
#initialize(attrs) ⇒ ClassConfig
Returns a new instance of ClassConfig.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Instance Attribute Details
#belongs_tos ⇒ Object
Returns the value of attribute belongs_tos.
9 10 11 |
# File 'lib/vorpal/config/class_config.rb', line 9 def belongs_tos @belongs_tos end |
#db_class ⇒ Object (readonly)
Returns the value of attribute db_class.
8 9 10 |
# File 'lib/vorpal/config/class_config.rb', line 8 def db_class @db_class end |
#deserializer ⇒ Object (readonly)
Returns the value of attribute deserializer.
8 9 10 |
# File 'lib/vorpal/config/class_config.rb', line 8 def deserializer @deserializer end |
#domain_class ⇒ Object (readonly)
Returns the value of attribute domain_class.
8 9 10 |
# File 'lib/vorpal/config/class_config.rb', line 8 def domain_class @domain_class end |
#has_manys ⇒ Object
Returns the value of attribute has_manys.
9 10 11 |
# File 'lib/vorpal/config/class_config.rb', line 9 def has_manys @has_manys end |
#has_ones ⇒ Object
Returns the value of attribute has_ones.
9 10 11 |
# File 'lib/vorpal/config/class_config.rb', line 9 def has_ones @has_ones end |
#local_association_configs ⇒ Object (readonly)
Returns the value of attribute local_association_configs.
8 9 10 |
# File 'lib/vorpal/config/class_config.rb', line 8 def local_association_configs @local_association_configs end |
#primary_key_type ⇒ Object (readonly)
Returns the value of attribute primary_key_type.
8 9 10 |
# File 'lib/vorpal/config/class_config.rb', line 8 def primary_key_type @primary_key_type end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
8 9 10 |
# File 'lib/vorpal/config/class_config.rb', line 8 def serializer @serializer end |
Instance Method Details
#build_db_object(attributes) ⇒ Object
27 28 29 |
# File 'lib/vorpal/config/class_config.rb', line 27 def build_db_object(attributes) db_class.new(attributes) end |
#deserialize(db_object) ⇒ Object
47 48 49 50 |
# 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) ⇒ Object
56 57 58 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/vorpal/config/class_config.rb', line 35 def get_db_object_attributes(db_object) symbolize_keys(db_object.attributes) end |
#serialization_required? ⇒ Boolean
39 40 41 |
# File 'lib/vorpal/config/class_config.rb', line 39 def serialization_required? domain_class.superclass.name != 'ActiveRecord::Base' end |
#serialize(object) ⇒ Object
43 44 45 |
# File 'lib/vorpal/config/class_config.rb', line 43 def serialize(object) serializer.serialize(object) end |
#set_attribute(db_object, attribute, value) ⇒ Object
52 53 54 |
# 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) ⇒ Object
31 32 33 |
# File 'lib/vorpal/config/class_config.rb', line 31 def set_db_object_attributes(db_object, attributes) db_object.attributes = attributes end |