class Joiner::Path

Constants

AGGREGATE_MACROS

Attributes

base[R]
path[R]

Public Class Methods

new(base, path) click to toggle source
# File lib/joiner/path.rb, line 4
def initialize(base, path)
  @base, @path = base, path
end

Public Instance Methods

aggregate?() click to toggle source
# File lib/joiner/path.rb, line 8
def aggregate?
  macros.any? { |macro| AGGREGATE_MACROS.include? macro }
end
macros() click to toggle source
# File lib/joiner/path.rb, line 12
def macros
  reflections.collect(&:macro)
end
model() click to toggle source
# File lib/joiner/path.rb, line 16
def model
  path.empty? ? base : reflections.last.try(:klass)
end

Private Instance Methods

reflections() click to toggle source
# File lib/joiner/path.rb, line 24
def reflections
  klass = base
  path.collect { |reference|
    klass.reflect_on_association(reference).tap { |reflection|
      if reflection.nil?
        raise Joiner::AssociationNotFound,
          "No association matching #{base.name}, #{path.join(', ')}"
      end

      klass = reflection.klass
    }
  }
end