class Nazrin::DataAccessor::Struct
Attributes
config[R]
Public Class Methods
[](config)
click to toggle source
# 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()
click to toggle source
# 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
Public Instance Methods
data_from_response(res)
click to toggle source
# 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)
click to toggle source
# File lib/nazrin/data_accessor/struct.rb, line 28 def load_all(data) data.map do |attributes| model.new(attributes) end end