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
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
A new instance of Base.
- #needle ⇒ Object
- #primary_key_columns ⇒ Object
-
#validate! ⇒ Object
VALIDATE.
Constructor Details
#initialize(object_class, object_data) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 |
# File 'lib/table_sync/orm_adapter/base.rb', line 7 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
87 88 89 |
# File 'lib/table_sync/orm_adapter/base.rb', line 87 def self.model_naming raise NotImplementedError end |
Instance Method Details
#attributes ⇒ Object
:nocov:
83 84 85 |
# File 'lib/table_sync/orm_adapter/base.rb', line 83 def attributes raise NotImplementedError end |
#attributes_for_destroy ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/table_sync/orm_adapter/base.rb', line 46 def attributes_for_destroy if object.respond_to?(:attributes_for_destroy) object.attributes_for_destroy else needle end end |
#attributes_for_headers ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/table_sync/orm_adapter/base.rb', line 62 def attributes_for_headers if object.respond_to?(:attributes_for_headers) object.attributes_for_headers else attributes end end |
#attributes_for_routing_key ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/table_sync/orm_adapter/base.rb', line 54 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
38 39 40 41 42 43 44 |
# File 'lib/table_sync/orm_adapter/base.rb', line 38 def attributes_for_update if object.respond_to?(:attributes_for_sync) object.attributes_for_sync else attributes end end |
#empty? ⇒ Boolean
MISC
76 77 78 |
# File 'lib/table_sync/orm_adapter/base.rb', line 76 def empty? object.nil? end |
#find ⇒ Object
28 29 30 |
# File 'lib/table_sync/orm_adapter/base.rb', line 28 def find self end |
#init ⇒ Object
FIND OR INIT OBJECT
24 25 26 |
# File 'lib/table_sync/orm_adapter/base.rb', line 24 def init self end |
#needle ⇒ Object
32 33 34 |
# File 'lib/table_sync/orm_adapter/base.rb', line 32 def needle object_data.slice(*primary_key_columns) end |
#primary_key_columns ⇒ Object
70 71 72 |
# File 'lib/table_sync/orm_adapter/base.rb', line 70 def primary_key_columns Array.wrap(object_class.primary_key).map(&:to_sym) end |
#validate! ⇒ Object
VALIDATE
16 17 18 19 20 |
# File 'lib/table_sync/orm_adapter/base.rb', line 16 def validate! if (primary_key_columns - object_data.keys).any? raise TableSync::NoPrimaryKeyError.new(object_class, object_data, primary_key_columns) end end |