Sha256: c1042ba1c14142ac9ddac6ad5d50559df084def42fb78aa3884dbd1358ac4e50

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module EacRailsUtils::Models::TablelessAssociations
  module ActiveRecordReflection
    extend ActiveSupport::Concern

    included do
      if ActiveRecord.version >= Gem::Version.new("4.1.2")
        class_attribute :_reflections
        self._reflections = ActiveSupport::HashWithIndifferentAccess.new
      else
        class_attribute :reflections
        self.reflections = {}
      end
    end

    module ClassMethods
      if ActiveRecord.version < Gem::Version.new("4.1")
        def create_reflection(macro, name, scope, options, active_record)
          case macro
          when :has_many, :belongs_to
            klass =  ActiveRecord::Reflection::AssociationReflection
            reflection = klass.new(macro, name, scope, options, active_record)
          end

          self.reflections = self.reflections.merge(name => reflection)
          reflection
        end
      end

      def reflect_on_association(association)
        if ActiveRecord.version >= Gem::Version.new("4.1.2")
          _reflections[association.to_s]
        else
          reflections[association]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eac_rails_utils-0.22.0 lib/eac_rails_utils/models/tableless_associations/active_record_reflection.rb
eac_rails_utils-0.21.0 lib/eac_rails_utils/models/tableless_associations/active_record_reflection.rb