class Datamappify::Repository::QueryMethod::Method
Provides a default set of methods to the varies {QueryMethod} classes
Attributes
@return [Data::Mapper]
@return [UnitOfWork::PersistentStates]
Public Class Methods
@param options [Hash]
a hash containing required items like data_mapper and states
@param entity [Entity]
@param args [any]
# File lib/datamappify/repository/query_method/method.rb, line 20 def initialize(options, entity = nil, *args) @data_mapper = options[:data_mapper] @states = options[:states] @lazy_load = options[:lazy_load?] @entity = entity end
Public Instance Methods
Should the method be aware of the dirty state? i.e. {Find} probably doesn’t whereas {Save} does
@note Override this method for individual query methods
@return [Boolean]
# File lib/datamappify/repository/query_method/method.rb, line 33 def dirty_aware? false end
The method is for reading data?
@note Override this method for individual query methods
@return [Boolean]
# File lib/datamappify/repository/query_method/method.rb, line 42 def reader? false end
The method is for writing data?
@note Override this method for individual query methods
@return [Boolean]
# File lib/datamappify/repository/query_method/method.rb, line 51 def writer? false end
Private Instance Methods
Walks through the attributes and performs actions on them
@param entity [Entity]
@yield (see SourceAttributesWalker#execute
)
@yieldparam (see SourceAttributesWalker#execute
)
@yieldreturn (see SourceAttributesWalker#execute
)
@return [void]
@see SourceAttributesWalker#execute
# File lib/datamappify/repository/query_method/method.rb, line 108 def attributes_walker(entity, &block) UnitOfWork::Transaction.new(data_mapper) do data_mapper.classified_attributes.each do |provider_name, attributes| source_attributes_walker.new({ :entity => entity, :provider_name => provider_name, :attributes => attributes, :dirty_aware? => dirty_aware?, :dirty_attributes => states.find(entity).changed, :query_method => self }).execute(&block) end end end
Dispatches a {Criteria} according to the {Data::Mapper data mapper}‘s default provider and default source class
@param criteria_name [Symbol]
@param args [any]
# File lib/datamappify/repository/query_method/method.rb, line 63 def dispatch_criteria_to_default_source(criteria_name, *args) data_mapper.default_provider.build_criteria( criteria_name, data_mapper.default_source_class, *args ) end
Dispatches a {Criteria} via {#attributes_walker}
@param criteria_name [Symbol]
@param entity [Entity]
@return [void]
# File lib/datamappify/repository/query_method/method.rb, line 76 def dispatch_criteria_to_providers(criteria_name, entity) _primary_record = nil attributes_walker(entity) do |provider_name, source_class, attributes| attributes.classify { |attr| attr.options[:via] }.each do |via, attrs| record = data_mapper.provider(provider_name).build_criteria( criteria_name, source_class, entity, attrs, :via => via, :primary_record => _primary_record ) _primary_record ||= record end end end
# File lib/datamappify/repository/query_method/method.rb, line 123 def source_attributes_walker if @lazy_load Lazy::SourceAttributesWalker else SourceAttributesWalker end end