Class: TapRep::Models::Base
- Inherits:
-
Struct
- Object
- Struct
- TapRep::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
- .key_property ⇒ Object
- .path ⇒ Object
- .schema(&block) ⇒ Object
- .stream ⇒ Object
- .subclasses ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
7 8 9 |
# File 'lib/models/base.rb', line 7 def client @client end |
#data ⇒ Object
Returns the value of attribute data
7 8 9 |
# File 'lib/models/base.rb', line 7 def data @data end |
Class Method Details
.key_property ⇒ Object
20 21 22 |
# File 'lib/models/base.rb', line 20 def self.key_property :id end |
.path ⇒ Object
12 13 14 |
# File 'lib/models/base.rb', line 12 def self.path raise 'Implement #path in a subclass' end |
.schema(&block) ⇒ Object
24 25 26 27 28 |
# File 'lib/models/base.rb', line 24 def self.schema(&block) @schema ||= ::TapRep::Schema.new(stream, key_property) @schema.instance_eval(&block) if block_given? @schema.to_hash end |
.stream ⇒ Object
16 17 18 |
# File 'lib/models/base.rb', line 16 def self.stream raise 'Implement #stream in a subclass' end |
.subclasses ⇒ Object
8 9 10 |
# File 'lib/models/base.rb', line 8 def self.subclasses ObjectSpace.each_object(Class).select { |klass| klass < self } end |
Instance Method Details
#base_record ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/models/base.rb', line 34 def base_record { type: 'RECORD', stream: self.class.stream, record: transform } end |
#extra_records ⇒ Object
42 43 44 |
# File 'lib/models/base.rb', line 42 def extra_records [] end |
#records ⇒ Object
46 47 48 |
# File 'lib/models/base.rb', line 46 def records [base_record] + extra_records.map(&:records) end |
#transform ⇒ Object
30 31 32 |
# File 'lib/models/base.rb', line 30 def transform data.dup end |