Class: Datamappify::Repository::QueryMethod::Method
- Inherits:
-
Object
- Object
- Datamappify::Repository::QueryMethod::Method
- Defined in:
- lib/datamappify/repository/query_method/method.rb,
lib/datamappify/repository/query_method/method/source_attributes_walker.rb
Overview
Provides a default set of methods to the varies Datamappify::Repository::QueryMethod classes
Defined Under Namespace
Classes: SourceAttributesWalker
Instance Attribute Summary collapse
- #data_mapper ⇒ Data::Mapper readonly
- #states ⇒ UnitOfWork::PersistentStates readonly
Instance Method Summary collapse
-
#attributes_walker(entity) {|provider_name, source_class, attributes| ... } ⇒ void
private
Walks through the attributes and performs actions on them.
-
#dirty_aware? ⇒ Boolean
Should the method be aware of the dirty state? i.e.
-
#dispatch_criteria_to_default_source(criteria_name, *args) ⇒ Object
private
Dispatches a Criteria according to the data mapper‘s default provider and default source class.
-
#dispatch_criteria_to_providers(criteria_name, entity) ⇒ void
private
Dispatches a Criteria via #attributes_walker.
-
#initialize(options, entity = nil, *args) ⇒ Method
constructor
A new instance of Method.
-
#reader? ⇒ Boolean
The method is for reading data?.
- #source_attributes_walker ⇒ Object private
-
#writer? ⇒ Boolean
The method is for writing data?.
Constructor Details
#initialize(options, entity = nil, *args) ⇒ Method
Returns a new instance of Method.
20 21 22 23 24 25 |
# File 'lib/datamappify/repository/query_method/method.rb', line 20 def initialize(, entity = nil, *args) @data_mapper = [:data_mapper] @states = [:states] @lazy_load = [:lazy_load?] @entity = entity end |
Instance Attribute Details
#data_mapper ⇒ Data::Mapper (readonly)
9 10 11 |
# File 'lib/datamappify/repository/query_method/method.rb', line 9 def data_mapper @data_mapper end |
#states ⇒ UnitOfWork::PersistentStates (readonly)
12 13 14 |
# File 'lib/datamappify/repository/query_method/method.rb', line 12 def states @states end |
Instance Method Details
#attributes_walker(entity) {|provider_name, source_class, attributes| ... } ⇒ void (private)
This method returns an undefined value.
Walks through the attributes and performs actions on them
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# 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 |
#dirty_aware? ⇒ Boolean
33 34 35 |
# File 'lib/datamappify/repository/query_method/method.rb', line 33 def dirty_aware? false end |
#dispatch_criteria_to_default_source(criteria_name, *args) ⇒ Object (private)
Dispatches a Criteria according to the data mapper‘s default provider and default source class
63 64 65 66 67 |
# 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 |
#dispatch_criteria_to_providers(criteria_name, entity) ⇒ void (private)
This method returns an undefined value.
Dispatches a Criteria via #attributes_walker
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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.[: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 |
#reader? ⇒ Boolean
Override this method for individual query methods
The method is for reading data?
42 43 44 |
# File 'lib/datamappify/repository/query_method/method.rb', line 42 def reader? false end |
#source_attributes_walker ⇒ Object (private)
123 124 125 126 127 128 129 |
# File 'lib/datamappify/repository/query_method/method.rb', line 123 def source_attributes_walker if @lazy_load Lazy::SourceAttributesWalker else SourceAttributesWalker end end |
#writer? ⇒ Boolean
Override this method for individual query methods
The method is for writing data?
51 52 53 |
# File 'lib/datamappify/repository/query_method/method.rb', line 51 def writer? false end |