Class: Elasticsearch::Model::Extensions::DependencyTracking::DependencyTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ DependencyTracker



6
7
8
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 6

def initialize(base)
  @base = base
end

Instance Method Details

#baseObject



10
11
12
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 10

def base
  @base
end

#dependent_custom_attributesHash<Array<String>, Array<String>>



15
16
17
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 15

def dependent_custom_attributes
  @dependent_custom_attributes
end

#dependent_custom_attributes=(new_value) ⇒ Object



20
21
22
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 20

def dependent_custom_attributes=(new_value)
  @dependent_custom_attributes = new_value
end

#each_dependent_attribute_for(changed_attributes) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 25

def each_dependent_attribute_for(changed_attributes)
  dependent_custom_attributes.each do |attributes, dependent_attributes|
    dependent_attributes.each do |dependent_attribute|
      attributes.each do |a|
        yield dependent_attribute if changed_attributes.include? a
      end
    end
  end
end

#has_association_named?(table_name) ⇒ Boolean



43
44
45
46
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 43

def has_association_named?(table_name)
  # TODO call `reflect_on_all_associations` through a proxy object
  base.reflect_on_all_associations.any? { |a| a.name == table_name }
end

#has_dependent_fields?(field) ⇒ Boolean



36
37
38
39
40
# File 'lib/elasticsearch/model/extensions/dependency_tracking/dependency_tracker.rb', line 36

def has_dependent_fields?(field)
  dependent_custom_attributes.any? do |from, to|
    from.include? field.to_s
  end
end