Sha256: e510b1c4e364912c9cfc9237bce68dfa55f20cb6efbbb47b94dd79dda429c810

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Onoma
  class Reflection
    attr_reader :active_record, :name, :class_name, :foreign_key, :scope, :options, :nomenclature, :klass

    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
      @scope = options[:scope]
      @nomenclature = class_name.underscore.pluralize
      @klass = Onoma.find(@nomenclature)
    end

    alias_method :model, :active_record

    def macro
      :belongs_to
    end

    # 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.
    def ==(other_aggregation)
      other_aggregation.is_a?(self.class) &&
        name == other_aggregation.name &&
        !other_aggregation.options.nil? &&
        active_record == other_aggregation.active_record
    end

    def all(*args)
      @klass ? @klass.all(*args) : []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onoma-0.0.0 lib/onoma/reflection.rb