Class: Hold::Sequel::PropertyMapper::CustomQuery
- Inherits:
-
Hold::Sequel::PropertyMapper
- Object
- Hold::Sequel::PropertyMapper
- Hold::Sequel::PropertyMapper::CustomQuery
- Defined in:
- lib/hold/sequel/property_mapper/custom_query.rb
Overview
A read-only mapper for array properties, which allows you to fetch the items via an arbitrary custom query against a target repository. You supply a block which takes the dataset and mapper arguments supplied by the repository’s query_for_version method, but also an additional ID argument for the ID of the object for which the property is being fetched.
example:
map_custom_query('foos') do |id, dataset, mapping|
dataset.join(:bar, ...).
...
.filter(:boz_id => id)
end
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#target_repo ⇒ Object
Returns the value of attribute target_repo.
Attributes inherited from Hold::Sequel::PropertyMapper
#property, #property_name, #repository
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(repo, property_name, options = {}, &block) ⇒ CustomQuery
constructor
A new instance of CustomQuery.
- #load_value(row = nil, id = nil, version = nil) ⇒ Object
Methods inherited from Hold::Sequel::PropertyMapper
#build_insert_row, #build_update_row, #columns_aliases_and_tables_for_select, #load_values, #make_filter, #make_multi_filter, #post_delete, #post_insert, #post_update, #pre_delete, #pre_insert, #pre_update
Constructor Details
#initialize(repo, property_name, options = {}, &block) ⇒ CustomQuery
Returns a new instance of CustomQuery.
22 23 24 25 26 |
# File 'lib/hold/sequel/property_mapper/custom_query.rb', line 22 def initialize(repo, property_name, ={}, &block) super(repo, property_name, &nil) # re &nil: our &block is otherwise implicitly passed on to super it seems, bit odd @model_class = [:model_class] or raise ArgumentError @query_block = [:query] || block end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
19 20 21 |
# File 'lib/hold/sequel/property_mapper/custom_query.rb', line 19 def model_class @model_class end |
#target_repo ⇒ Object
Returns the value of attribute target_repo.
20 21 22 |
# File 'lib/hold/sequel/property_mapper/custom_query.rb', line 20 def target_repo @target_repo end |
Class Method Details
.setter_dependencies_for(options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/hold/sequel/property_mapper/custom_query.rb', line 14 def self.setter_dependencies_for(={}) features = [*[:model_class]].map {|klass| [:get_class, klass]} {:target_repo => [IdentitySetRepository, *features]} end |
Instance Method Details
#load_value(row = nil, id = nil, version = nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/hold/sequel/property_mapper/custom_query.rb', line 28 def load_value(row=nil, id=nil, version=nil) target_repo.query(version) do |dataset, mapping| @query_block.call(id, dataset, mapping) end.to_a end |