Sha256: 2179fa244aebd41a7cae6b821c669803870d78de8ddef430196d79dee4ee38f0

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

module ErpBaseErpSvcs
  module Extensions
    module ActiveRecord
      module StiInstantiation
        module ActMacro
          def instantiates_with_sti
            include InstanceMethods
            extend ClassMethods
            instantiates_with_sti?
          end

          def instantiates_with_sti?
            included_modules.include?(ErpBaseErpSvcs::Extensions::ActiveRecord::StiInstantiation::InstanceMethods)
          end
        end

        module InstanceMethods
        end

        module ClassMethods
          def new(*args, &block)
            options = args.first.is_a?(Hash) ? args.first : {}
            type = options[:type] || options['type']
            klass = type.is_a?(Class) ? type : type.constantize if type

            if type and klass != self
              raise "STI instantiation error: class #{klass.name} should be a descendant of #{self.name}" unless klass < self
              klass.new(*args, &block)
            else
              super
            end
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
erp_base_erp_svcs-4.2.0 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-4.0.0 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.1.5 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.1.4 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.1.3 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.1.2 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.1.1 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.7 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.1.0 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.6 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.5 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.4 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.3 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.2 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.1 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
erp_base_erp_svcs-3.0.0 lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb