Sha256: 4621616462d725f73e94a99c2a40d56e7c851c94950418b0242cc6173501a493

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

module Mobility
=begin

Module loading ActiveRecord-specific classes for Mobility models.

=end
  module ActiveRecord
    autoload :BackendResetter,     "mobility/active_record/backend_resetter"
    autoload :ModelTranslation,    "mobility/active_record/model_translation"
    autoload :StringTranslation,   "mobility/active_record/string_translation"
    autoload :TextTranslation,     "mobility/active_record/text_translation"
    autoload :Translation,         "mobility/active_record/translation"
    autoload :UniquenessValidator, "mobility/active_record/uniqueness_validator"

    def changes_applied
      @previously_changed = changes
      super
    end

    def clear_changes_information
      @previously_changed = ActiveSupport::HashWithIndifferentAccess.new
      super
    end

    def previous_changes
      super.merge(@previously_changed ||= ActiveSupport::HashWithIndifferentAccess.new)
    end

    def self.included(model_class)
      model_class.extend(ClassMethods)
      model_class.const_set(:UniquenessValidator,
                            Class.new(::Mobility::ActiveRecord::UniquenessValidator))
    end

    module ClassMethods
      # @return [ActiveRecord::Relation] relation extended with Mobility query methods.
      define_method ::Mobility.query_method do
        all
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mobility-0.1.17 lib/mobility/active_record.rb
mobility-0.1.16 lib/mobility/active_record.rb
mobility-0.1.15 lib/mobility/active_record.rb