Class: Hold::Sequel::PropertyMapper::CustomQuerySingleValue
- Inherits:
-
Hold::Sequel::PropertyMapper
- Object
- Hold::Sequel::PropertyMapper
- Hold::Sequel::PropertyMapper::CustomQuerySingleValue
- Defined in:
- lib/hold/sequel/property_mapper/custom_query_single_value.rb
Overview
A read-only mapper for properties which are a single instance of a model class loaded from another repo.
It allows you to fetch the item via an arbitrary custom query against the 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_single_value('foo') 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) ⇒ CustomQuerySingleValue
constructor
A new instance of CustomQuerySingleValue.
- #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) ⇒ CustomQuerySingleValue
Returns a new instance of CustomQuerySingleValue.
24 25 26 27 28 |
# File 'lib/hold/sequel/property_mapper/custom_query_single_value.rb', line 24 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 = block end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
21 22 23 |
# File 'lib/hold/sequel/property_mapper/custom_query_single_value.rb', line 21 def model_class @model_class end |
#target_repo ⇒ Object
Returns the value of attribute target_repo.
22 23 24 |
# File 'lib/hold/sequel/property_mapper/custom_query_single_value.rb', line 22 def target_repo @target_repo end |
Class Method Details
.setter_dependencies_for(options = {}) ⇒ Object
16 17 18 19 |
# File 'lib/hold/sequel/property_mapper/custom_query_single_value.rb', line 16 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
30 31 32 33 34 |
# File 'lib/hold/sequel/property_mapper/custom_query_single_value.rb', line 30 def load_value(row=nil, id=nil, version=nil) target_repo.query(version) do |dataset, mapping| @query_block.call(id, dataset, mapping) end.single_result end |