Sha256: be7b4709979fbed58d68db9d817cfcc1aa2b9e12d6403735625a5126724b6086

Contents?: true

Size: 1.13 KB

Versions: 29

Compression:

Stored size: 1.13 KB

Contents

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

    # name:       things
    # class_name: Thing
    # klass:      Onoma::Thing
    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

    alias 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

29 entries across 29 versions & 1 rubygems

Version Path
onoma-0.9.3 lib/onoma/reflection.rb
onoma-0.9.2 lib/onoma/reflection.rb
onoma-0.9.1 lib/onoma/reflection.rb
onoma-0.9.0 lib/onoma/reflection.rb
onoma-0.8.9 lib/onoma/reflection.rb
onoma-0.8.8 lib/onoma/reflection.rb
onoma-0.8.7 lib/onoma/reflection.rb
onoma-0.8.6 lib/onoma/reflection.rb
onoma-0.8.5 lib/onoma/reflection.rb
onoma-0.8.4 lib/onoma/reflection.rb
onoma-0.8.3 lib/onoma/reflection.rb
onoma-0.8.2 lib/onoma/reflection.rb
onoma-0.8.1 lib/onoma/reflection.rb
onoma-0.8.0 lib/onoma/reflection.rb
onoma-0.7.0 lib/onoma/reflection.rb
onoma-0.6.4 lib/onoma/reflection.rb
onoma-0.6.3 lib/onoma/reflection.rb
onoma-0.6.2 lib/onoma/reflection.rb
onoma-0.6.0 lib/onoma/reflection.rb
onoma-0.5.6 lib/onoma/reflection.rb