Class: ModelExplorer::Export
- Inherits:
-
Object
- Object
- ModelExplorer::Export
- Defined in:
- lib/model_explorer/export.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(record:, associations: []) ⇒ Export
constructor
A new instance of Export.
- #to_json ⇒ Object
Constructor Details
#initialize(record:, associations: []) ⇒ Export
Returns a new instance of Export.
8 9 10 11 12 13 14 15 16 |
# File 'lib/model_explorer/export.rb', line 8 def initialize(record:, associations: []) @record = record @associations = associations @data = nil unless record.is_a?(ModelExplorer::Record) raise ArgumentError, "Record must be an instance of ModelExplorer::Record" end end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
4 5 6 |
# File 'lib/model_explorer/export.rb', line 4 def associations @associations end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/model_explorer/export.rb', line 3 def record @record end |
Instance Method Details
#data ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/model_explorer/export.rb', line 22 def data @data ||= { model: record.klass.name, attributes: filtered_attributes, associations: fetch_associations } end |
#to_json ⇒ Object
18 19 20 |
# File 'lib/model_explorer/export.rb', line 18 def to_json(*) data.to_json end |