Class: Nazrin::DataAccessor::Struct
- Inherits:
-
Nazrin::DataAccessor
- Object
- Nazrin::DataAccessor
- Nazrin::DataAccessor::Struct
- Defined in:
- lib/nazrin/data_accessor/struct.rb,
lib/nazrin/data_accessor/struct/attribute_transformer.rb
Defined Under Namespace
Classes: AttributeTransformer, MissingDomainNameConfigError
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
Attributes inherited from Nazrin::DataAccessor
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Nazrin::DataAccessor
accessor_for, accessors, for, #initialize, register, register_accessor, registered_accessor_for, #results
Constructor Details
This class inherits a constructor from Nazrin::DataAccessor
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/nazrin/data_accessor/struct.rb', line 9 def config @config end |
Class Method Details
.[](config) ⇒ Object
11 12 13 14 15 |
# File 'lib/nazrin/data_accessor/struct.rb', line 11 def [](config) Class.new(self).tap do |clazz| clazz.instance_variable_set(:@config, config) end end |
.attribute_transformer ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/nazrin/data_accessor/struct.rb', line 17 def attribute_transformer return @attribute_transformer if defined?(@attribute_transformer) if config.attribute_transformer @attribute_transformer = config.attribute_transformer else @attribute_transformer = AttributeTransformer.new(config) end end |
Instance Method Details
#data_from_response(res) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/nazrin/data_accessor/struct.rb', line 34 def data_from_response(res) res.data[:hits][:hit].map do |hit| self.class.attribute_transformer.call( { 'id' => hit[:id] }.merge(hit[:fields] || {}) ) end end |
#load_all(data) ⇒ Object
28 29 30 31 32 |
# File 'lib/nazrin/data_accessor/struct.rb', line 28 def load_all(data) data.map do |attributes| model.new(attributes) end end |