class ROM::Associations::Definitions::Abstract

Abstract association definition object

@api public

Public Class Methods

new(source, target, **opts) click to toggle source

Instantiate a new association definition

@param [Symbol] source The name of the source dataset @param [Symbol] target The name of the target dataset @param [Hash] opts The option hash @option opts [Symbol] :as The name of the association (defaults to target) @option opts [Symbol] :relation The name of the target relation (defaults to target) @option opts [Symbol] :foreign_key The name of a custom foreign key @option opts [Symbol] :view The name of a custom relation view on the target's relation side @option opts [TrueClass,FalseClass] :override Whether provided :view should override association's default view

@api public

Calls superclass method
# File lib/rom/associations/definitions/abstract.rb, line 76
def self.new(source, target, **opts)
  source_name = Relation::Name[source]
  target_name = resolve_target_name(target, opts)
  options = process_options(target_name, Hash[opts])

  super(source_name, target_name, **options)
end
process_options(target, options) click to toggle source

@api private

# File lib/rom/associations/definitions/abstract.rb, line 93
def self.process_options(target, options)
  through = options[:through]

  if through
    options[:through] = ThroughIdentifier[through, target.relation, options[:assoc]]
  end

  options[:name] = target.relation

  options
end
resolve_target_name(target, options) click to toggle source

@api private

# File lib/rom/associations/definitions/abstract.rb, line 85
def self.resolve_target_name(target, options)
  dataset = target
  relation = options.fetch(:relation, target)

  Relation::Name[relation, dataset, options[:as]]
end

Public Instance Methods

aliased?() click to toggle source

Return true if association is aliased

@return [Boolean]

@api public

# File lib/rom/associations/definitions/abstract.rb, line 119
def aliased?
  options.key?(:as)
end
override?() click to toggle source

Return true if association's default relation view should be overridden by a custom one

@return [Boolean]

@api public

# File lib/rom/associations/definitions/abstract.rb, line 110
def override?
  options[:override].equal?(true)
end
type() click to toggle source

Return association class for a given definition object

@return [Class]

@api public

# File lib/rom/associations/definitions/abstract.rb, line 128
def type
  Inflector.demodulize(self.class.name).to_sym
end