Sha256: 66954f787cebdd9234c341dcecbdf496766d6d2bdb2329335c125bc65c9bf7e8

Contents?: true

Size: 1.28 KB

Versions: 15

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true
require_relative "./active_record/backend"
require_relative "./active_record/dirty"
require_relative "./active_record/cache"
require_relative "./active_record/query"
require_relative "./active_record/uniqueness_validation"
require_relative "./active_record/column_fallback"

module Mobility
=begin

Plugin for ActiveRecord models. This plugin automatically requires activerecord
related plugins, which are not actually "active" unless their base plugin (e.g.
dirty for active_record_dirty) is also enabled.

=end
  module Plugins
    module ActiveRecord
      extend Plugin

      requires :arel

      requires :active_record_backend, include: :after
      requires :active_record_dirty
      requires :active_record_cache
      requires :active_record_query
      requires :active_record_uniqueness_validation
      requires :active_record_column_fallback


      included_hook do |klass|
        unless active_record_class?(klass)
          name = klass.name || klass.to_s
          raise TypeError, "#{name} should be a subclass of ActiveRecord::Base to use the active_record plugin"
        end
      end

      private

      def active_record_class?(klass)
        klass < ::ActiveRecord::Base
      end
    end

    register_plugin(:active_record, ActiveRecord)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mobility-1.3.1 lib/mobility/plugins/active_record.rb
mobility-1.3.0 lib/mobility/plugins/active_record.rb
mobility-1.3.0.rc3 lib/mobility/plugins/active_record.rb
mobility-1.3.0.rc2 lib/mobility/plugins/active_record.rb
mobility-1.3.0.rc1 lib/mobility/plugins/active_record.rb
mobility-1.2.9 lib/mobility/plugins/active_record.rb
mobility-1.2.8 lib/mobility/plugins/active_record.rb
mobility-1.2.7 lib/mobility/plugins/active_record.rb
mobility-1.2.6 lib/mobility/plugins/active_record.rb
mobility-1.2.5 lib/mobility/plugins/active_record.rb
mobility-1.2.4 lib/mobility/plugins/active_record.rb
mobility-1.2.3 lib/mobility/plugins/active_record.rb
mobility-1.2.2 lib/mobility/plugins/active_record.rb
mobility-1.2.1 lib/mobility/plugins/active_record.rb
mobility-1.2.0 lib/mobility/plugins/active_record.rb