Sha256: dc2d18c7189174caf15ceb539d0715c7e237fea32cac04cc0040e7ab574ae392

Contents?: true

Size: 715 Bytes

Versions: 3

Compression:

Stored size: 715 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Traits
  class Association
    module Members
      def from
        @from_class.traits
      end

      # Returns the actual association establisher class
      def from_class
        @from_class
      end

      # Returns the actual associated class
      def to
        reflection.klass.traits unless polymorphic?
      end

      def to_class
        reflection.klass unless polymorphic?
      end

      def self_to_self?
        from_class == to_class
      end

      def to_hash
        super.merge!(
          from:         from.name,
          to:           to.try(:name),
          self_to_self: self_to_self?
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-traits-1.0.3 lib/traits/association/members.rb
activerecord-traits-1.0.2 lib/traits/association/members.rb
activerecord-traits-1.0.1 lib/traits/association/members.rb