Class: TableSync::ORMAdapter::Base
- Inherits:
-
Object
- Object
- TableSync::ORMAdapter::Base
- Defined in:
- lib/table_sync/orm_adapter/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#object_class ⇒ Object
readonly
Returns the value of attribute object_class.
-
#object_data ⇒ Object
readonly
Returns the value of attribute object_data.
Class Method Summary collapse
-
.model_naming ⇒ Object
:nocov:.
Instance Method Summary collapse
-
#attributes ⇒ Object
:nocov:.
- #attributes_for_destroy ⇒ Object
- #attributes_for_headers ⇒ Object
- #attributes_for_routing_key ⇒ Object
-
#attributes_for_update ⇒ Object
ATTRIBUTES.
-
#empty? ⇒ Boolean
MISC.
- #find ⇒ Object
-
#init ⇒ Object
FIND OR INIT OBJECT.
-
#initialize(object_class, object_data) ⇒ Base
constructor
:nocov:.
- #needle ⇒ Object
- #primary_key_columns ⇒ Object
-
#validate! ⇒ Object
VALIDATE.
Constructor Details
#initialize(object_class, object_data) ⇒ Base
:nocov:
13 14 15 16 17 18 |
# File 'lib/table_sync/orm_adapter/base.rb', line 13 def initialize(object_class, object_data) @object_class = object_class @object_data = object_data.symbolize_keys validate! end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/table_sync/orm_adapter/base.rb', line 5 def object @object end |
#object_class ⇒ Object (readonly)
Returns the value of attribute object_class.
5 6 7 |
# File 'lib/table_sync/orm_adapter/base.rb', line 5 def object_class @object_class end |
#object_data ⇒ Object (readonly)
Returns the value of attribute object_data.
5 6 7 |
# File 'lib/table_sync/orm_adapter/base.rb', line 5 def object_data @object_data end |
Class Method Details
.model_naming ⇒ Object
:nocov:
8 9 10 |
# File 'lib/table_sync/orm_adapter/base.rb', line 8 def self.model_naming raise NotImplementedError end |
Instance Method Details
#attributes ⇒ Object
:nocov:
89 90 91 |
# File 'lib/table_sync/orm_adapter/base.rb', line 89 def attributes raise NotImplementedError end |
#attributes_for_destroy ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/table_sync/orm_adapter/base.rb', line 52 def attributes_for_destroy if object.respond_to?(:attributes_for_destroy) object.attributes_for_destroy else attributes end end |
#attributes_for_headers ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/table_sync/orm_adapter/base.rb', line 68 def attributes_for_headers if object.respond_to?(:attributes_for_headers) object.attributes_for_headers else attributes end end |
#attributes_for_routing_key ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/table_sync/orm_adapter/base.rb', line 60 def attributes_for_routing_key if object.respond_to?(:attributes_for_routing_key) object.attributes_for_routing_key else attributes end end |
#attributes_for_update ⇒ Object
ATTRIBUTES
44 45 46 47 48 49 50 |
# File 'lib/table_sync/orm_adapter/base.rb', line 44 def attributes_for_update if object.respond_to?(:attributes_for_sync) object.attributes_for_sync else attributes end end |
#empty? ⇒ Boolean
MISC
82 83 84 |
# File 'lib/table_sync/orm_adapter/base.rb', line 82 def empty? object.nil? end |
#find ⇒ Object
34 35 36 |
# File 'lib/table_sync/orm_adapter/base.rb', line 34 def find self end |
#init ⇒ Object
FIND OR INIT OBJECT
30 31 32 |
# File 'lib/table_sync/orm_adapter/base.rb', line 30 def init self end |
#needle ⇒ Object
38 39 40 |
# File 'lib/table_sync/orm_adapter/base.rb', line 38 def needle object_data.slice(*primary_key_columns) end |
#primary_key_columns ⇒ Object
76 77 78 |
# File 'lib/table_sync/orm_adapter/base.rb', line 76 def primary_key_columns Array.wrap(object_class.primary_key).map(&:to_sym) end |
#validate! ⇒ Object
VALIDATE
22 23 24 25 26 |
# File 'lib/table_sync/orm_adapter/base.rb', line 22 def validate! if (primary_key_columns - object_data.keys).any? raise TableSync::NoPrimaryKeyError.new(object_class, object_data, primary_key_columns) end end |