class Datamappify::Repository::QueryMethod::Method::SourceAttributesWalker

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

Public Class Methods

new(options = {}) click to toggle source
# File lib/datamappify/repository/query_method/method/source_attributes_walker.rb, line 8
def initialize(options = {})
  @entity           = options[:entity]
  @provider_name    = options[:provider_name]
  @attributes       = options[:attributes]
  @dirty_aware      = options[:dirty_aware?]
  @dirty_attributes = options[:dirty_attributes]
  @query_method     = options[:query_method]
end

Public Instance Methods

execute(&block) click to toggle source

@yield [provider_name, source_class, attributes]

action to be performed on the attributes grouped by their source class

@yieldparam provider_name [String]

@yieldparam source_class [Class]

@yieldparam attributes [Set<Data::Mapper::Attribute>]

@yieldreturn [void]

@return [void]

# 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

Private Instance Methods

check_dirty?(attributes) click to toggle source

Only walk when it’s not dirty aware, or it has dirty attributes

@param attributes [Set<Data::Mapper::Attribute>]

@return [Boolean]

# File lib/datamappify/repository/query_method/method/source_attributes_walker.rb, line 65
def check_dirty?(attributes)
  !@dirty_aware || dirty?(attributes)
end
dirty?(attributes) click to toggle source

Whether the persistent state object is dirty

@param (see do_walk?)

@return [Boolean]

# 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) click to toggle source

Whether it is necessary to do the walk

@param source_class [Class]

@param attributes [Set<Data::Mapper::Attribute>]

@return [Boolean]

# File lib/datamappify/repository/query_method/method/source_attributes_walker.rb, line 47
def do_walk?(source_class, attributes)
  check_dirty?(attributes)
end
walk_performed(attributes) click to toggle source

A hook method for when a walk is performed

@param attributes [Set<Data::Mapper::Attribute>]

@return [void]

# 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