Sha256: 5029d78438c6401475ce667bcc35f1e36f6f4b980eee9b352f8a9f4b3d6c681c

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

module ActiveRecord
  module ActsAs
    module ReflectionsWithActsAs
      def _reflections
        super.reverse_merge(acting_as_model._reflections)
      end
    end

    module ClassMethods
      def self.included(module_)
        module_.prepend ReflectionsWithActsAs
      end

      def validators_on(*args)
        super + acting_as_model.validators_on(*args)
      end

      def actables
        acting_as_model.where(actable_id: select(:id))
      end

      def respond_to_missing?(method, include_private = false)
        acting_as_model.methods_callable_by_submodel.include?(method) || super
      end

      def method_missing(method, *args, &block)
        if acting_as_model.methods_callable_by_submodel.include?(method)
          result = acting_as_model.public_send(method, *args, &block)
          if result.is_a?(ActiveRecord::Relation)
            all.joins(acting_as_name.to_sym).merge(result)
          else
            result
          end
        else
          super
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
active_record-acts_as-5.0.2 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-5.0.1 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-5.0.0 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-4.0.3 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-4.0.2 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-4.0.1 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-4.0.0 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-3.1.0 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-3.0.2 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-3.0.1 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-3.0.0 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-2.5.0 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-2.4.2 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-2.4.1 lib/active_record/acts_as/class_methods.rb
active_record-acts_as-2.4.0 lib/active_record/acts_as/class_methods.rb