Class: SimpleQuery::ReadModel
- Inherits:
-
Object
- Object
- SimpleQuery::ReadModel
- Defined in:
- lib/simple_query/read_model.rb
Class Method Summary collapse
- .attribute(attr_name, column: attr_name) ⇒ Object
- .attributes ⇒ Object
- .build_from_row(row_hash) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ ReadModel
constructor
A new instance of ReadModel.
Constructor Details
#initialize ⇒ ReadModel
Returns a new instance of ReadModel.
23 |
# File 'lib/simple_query/read_model.rb', line 23 def initialize; end |
Class Method Details
.attribute(attr_name, column: attr_name) ⇒ Object
5 6 7 8 9 |
# File 'lib/simple_query/read_model.rb', line 5 def self.attribute(attr_name, column: attr_name) @attributes ||= {} @attributes[attr_name] = column.to_s attr_reader attr_name end |
.attributes ⇒ Object
11 12 13 |
# File 'lib/simple_query/read_model.rb', line 11 def self.attributes @attributes || {} end |
.build_from_row(row_hash) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/simple_query/read_model.rb', line 15 def self.build_from_row(row_hash) obj = allocate attributes.each do |attr_name, column_name| obj.instance_variable_set(:"@#{attr_name}", row_hash[column_name]) end obj end |