class QPath

Attributes

qpath[R]
segments[R]
start_model[R]

Public Class Methods

new(smodel, path_str) click to toggle source
# File lib/sequel/plugins/join_by_paths.rb, line 35
def initialize(smodel, path_str)
  @qpath = path_str
  @start_model = smodel
  segment
end

Public Instance Methods

==(other) click to toggle source

source: ..ruby-doc.org/core-2.6.5/Hash.html

# File lib/sequel/plugins/join_by_paths.rb, line 46
def ==(other)
  (self.class === other) &&
    (@start_model == other.start_model) &&
    (@qpath == other.qpath)
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/sequel/plugins/join_by_paths.rb, line 54
def hash
  @start_model.hash ^ @qpath.hash # XOR
end
segment() click to toggle source
# File lib/sequel/plugins/join_by_paths.rb, line 58
def segment
  @segments = []
  start_node = @start_model.create_path_node('')
  start_node.model_class = @start_model
  path_str = ''
  path_nodes = []
  start_node.path_str = path_str
  nodes = [start_node]
  nodes.concat(@qpath.split('/').map { |nstr| @start_model.create_path_node(nstr) })
  return unless nodes.size > 1

  nodes[0...-1].each_with_index do |node, i|
    nodes[i + 1].set_model_class_by_parent_model(node.model_class)
    path_nodes << nodes[i + 1]
    nodes[i + 1].path_str = path_nodes.join('/')
    @segments << [node, nodes[i + 1]]
  end
end
size() click to toggle source
# File lib/sequel/plugins/join_by_paths.rb, line 41
def size
  @segments.size
end