Module: Elasticsearch::Model::Extensions::DependencyTracking::ClassMethods

Defined in:
lib/elasticsearch/model/extensions/dependency_tracking.rb

Instance Method Summary collapse

Instance Method Details

#each_dependent_attribute_for(changed_attributes) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/elasticsearch/model/extensions/dependency_tracking.rb', line 22

def each_dependent_attribute_for(changed_attributes)
  const_get('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

Returns:

  • (Boolean)


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

def has_association_named?(table_name)
  reflect_on_all_associations.any? { |a| a.name == table_name }
end

#has_dependent_fields?(field) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/elasticsearch/model/extensions/dependency_tracking.rb', line 32

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

#tracks_attributes_dependencies(dependencies) ⇒ Object



18
19
20
# File 'lib/elasticsearch/model/extensions/dependency_tracking.rb', line 18

def tracks_attributes_dependencies(dependencies)
  const_set 'DEPENDENT_CUSTOM_ATTRIBUTES', dependencies.dup.freeze
end