class Elasticsearch::Model::Extensions::AssociationPathFinding::MappingNode
Public Class Methods
from_class(klass)
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 8 def self.from_class(klass) name = klass.document_type.intern new(klass: klass, name: name, mapping: klass.mapping.to_hash[name]) end
new(klass:, name:, mapping:, through_class:nil)
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 14 def initialize(klass:, name:, mapping:, through_class:nil) @klass = klass @name = name @mapping = mapping @through_class = through_class end
Public Instance Methods
each(&block)
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 37 def each(&block) associations = @klass.reflect_on_all_associations props = @mapping[:properties] fields = props.keys edges = fields.map { |f| a = associations.find { |a| a.name == f } if a && a.options[:polymorphic] != true through_class = if a.options[:through] a.options[:through].to_s.classify.constantize end dest = MappingNode.new(klass: a.class_name.constantize, name: f.to_s.pluralize.intern, mapping: props[f], through_class: through_class) edge_class.new(name: f, destination: dest) end }.reject(&:nil?) if block.nil? edges else edges.each(&block) end end
klass()
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 29 def klass @klass end
name()
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 21 def name @name end
relates_to_class?(klass)
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 25 def relates_to_class?(klass) @klass == klass || @through_class == klass end
through_class()
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/mapping_node.rb, line 33 def through_class @through_class end