Class: Vorpal::ClassConfig
- Inherits:
-
Object
- Object
- Vorpal::ClassConfig
- Defined in:
- lib/vorpal/configs.rb
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.
-
#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.
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_tos ⇒ Object
Returns the value of attribute belongs_tos.
133 134 135 |
# File 'lib/vorpal/configs.rb', line 133 def belongs_tos @belongs_tos end |
#db_class ⇒ Object (readonly)
Returns the value of attribute db_class.
132 133 134 |
# File 'lib/vorpal/configs.rb', line 132 def db_class @db_class end |
#deserializer ⇒ Object (readonly)
Returns the value of attribute deserializer.
132 133 134 |
# File 'lib/vorpal/configs.rb', line 132 def deserializer @deserializer end |
#domain_class ⇒ Object (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_manys ⇒ Object
Returns the value of attribute has_manys.
133 134 135 |
# File 'lib/vorpal/configs.rb', line 133 def has_manys @has_manys end |
#has_ones ⇒ Object
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_configs ⇒ Object (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 |
#serializer ⇒ Object (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
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 |