class Onoma::Reflection

Attributes

active_record[R]
class_name[R]
foreign_key[R]
klass[R]
model[R]
name[R]
nomenclature[R]
options[R]
scope[R]

Public Class Methods

new(active_record, name, options = {}) click to toggle source

name: things class_name: Thing klass: Onoma::Thing

# File lib/onoma/reflection.rb, line 8
def initialize(active_record, name, options = {})
  @options = options
  @name = name.to_s
  @active_record = active_record
  @class_name = options[:class_name] || name.to_s.classify
  @foreign_key = (options[:foreign_key] || name).to_s
  @scope = options[:scope]
  @nomenclature = class_name.tableize
  @klass = "Onoma::#{@class_name}".constantize
end

Public Instance Methods

==(other_aggregation) click to toggle source

Returns true if self and other_aggregation have the same name attribute, active_record attribute, and other_aggregation has an options hash assigned to it.

# File lib/onoma/reflection.rb, line 28
def ==(other_aggregation)
  other_aggregation.is_a?(self.class) &&
    name == other_aggregation.name &&
    !other_aggregation.options.nil? &&
    active_record == other_aggregation.active_record
end
all(*args) click to toggle source
# File lib/onoma/reflection.rb, line 35
def all(*args)
  @klass ? @klass.all(*args) : []
end
macro() click to toggle source
# File lib/onoma/reflection.rb, line 21
def macro
  :belongs_to
end