Class: Datamappify::Repository::QueryMethod::Method::SourceAttributesWalker
- Inherits:
-
Object
- Object
- Datamappify::Repository::QueryMethod::Method::SourceAttributesWalker
- Defined in:
- lib/datamappify/repository/query_method/method/source_attributes_walker.rb
Overview
Walks through the attributes of the source classes under a provider (e.g. ActiveRecord), the walker is aware of the dirty state so that certain operations (i.e. #save) can be bypassed
Direct Known Subclasses
Instance Method Summary collapse
-
#check_dirty?(attributes) ⇒ Boolean
private
Only walk when it’s not dirty aware, or it has dirty attributes.
-
#dirty?(attributes) ⇒ Boolean
private
Whether the persistent state object is dirty.
-
#do_walk?(source_class, attributes) ⇒ Boolean
private
Whether it is necessary to do the walk.
- #execute {|provider_name, source_class, attributes| ... } ⇒ void
-
#initialize(options = {}) ⇒ SourceAttributesWalker
constructor
A new instance of SourceAttributesWalker.
-
#walk_performed(attributes) ⇒ void
private
A hook method for when a walk is performed.
Constructor Details
#initialize(options = {}) ⇒ SourceAttributesWalker
Returns a new instance of SourceAttributesWalker.
8 9 10 11 12 13 14 15 |
# File 'lib/datamappify/repository/query_method/method/source_attributes_walker.rb', line 8 def initialize( = {}) @entity = [:entity] @provider_name = [:provider_name] @attributes = [:attributes] @dirty_aware = [:dirty_aware?] @dirty_attributes = [:dirty_attributes] @query_method = [:query_method] end |
Instance Method Details
#check_dirty?(attributes) ⇒ Boolean (private)
Only walk when it’s not dirty aware, or it has dirty attributes
65 66 67 |
# File 'lib/datamappify/repository/query_method/method/source_attributes_walker.rb', line 65 def check_dirty?(attributes) !@dirty_aware || dirty?(attributes) end |
#dirty?(attributes) ⇒ Boolean (private)
Whether the persistent state object is dirty
74 75 76 |
# File 'lib/datamappify/repository/query_method/method/source_attributes_walker.rb', line 74 def dirty?(attributes) (attributes.map(&:key) & @dirty_attributes).any? end |
#do_walk?(source_class, attributes) ⇒ Boolean (private)
Whether it is necessary to do the walk
47 48 49 |
# File 'lib/datamappify/repository/query_method/method/source_attributes_walker.rb', line 47 def do_walk?(source_class, attributes) check_dirty?(attributes) end |
#execute {|provider_name, source_class, attributes| ... } ⇒ void
This method returns an undefined value.
29 30 31 32 33 34 35 36 |
# File 'lib/datamappify/repository/query_method/method/source_attributes_walker.rb', line 29 def execute(&block) @attributes.classify(&:source_class).each do |source_class, attributes| if do_walk?(source_class, attributes) block.call(@provider_name, source_class, attributes) walk_performed(attributes) end end end |
#walk_performed(attributes) ⇒ void (private)
This method returns an undefined value.
A hook method for when a walk is performed
56 57 58 |
# File 'lib/datamappify/repository/query_method/method/source_attributes_walker.rb', line 56 def walk_performed(attributes) Logger.performed(@query_method && @query_method.class) end |