Class: TapClutch::Models::Base
- Inherits:
-
Struct
- Object
- Struct
- TapClutch::Models::Base
- Defined in:
- lib/models/base.rb
Overview
rubocop:disable Metrics/BlockLength
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
8 9 10 |
# File 'lib/models/base.rb', line 8 def client @client end |
#data ⇒ Object
Returns the value of attribute data
8 9 10 |
# File 'lib/models/base.rb', line 8 def data @data end |
Class Method Details
.key_property ⇒ Object
17 18 19 |
# File 'lib/models/base.rb', line 17 def self.key_property :id end |
.schema(&block) ⇒ Object
21 22 23 24 25 |
# File 'lib/models/base.rb', line 21 def self.schema(&block) @schema ||= ::TapClutch::Schema.new(stream, key_property) @schema.instance_eval(&block) if block_given? @schema.to_hash end |
.stream ⇒ Object
13 14 15 |
# File 'lib/models/base.rb', line 13 def self.stream raise 'Implement #stream in a subclass' end |
.subclasses ⇒ Object
9 10 11 |
# File 'lib/models/base.rb', line 9 def self.subclasses ObjectSpace.each_object(Class).select { |klass| klass < self } end |
Instance Method Details
#base_record ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/models/base.rb', line 31 def base_record { type: 'RECORD', stream: self.class.stream, record: transform } end |
#extra_records ⇒ Object
39 40 41 |
# File 'lib/models/base.rb', line 39 def extra_records [] end |
#records ⇒ Object
43 44 45 |
# File 'lib/models/base.rb', line 43 def records [base_record] + extra_records.compact.flat_map(&:records) end |
#transform ⇒ Object
27 28 29 |
# File 'lib/models/base.rb', line 27 def transform data.transform_keys(&:underscore) end |