Sha256: fd7a88606262be2144e69050122879850987f937b0978a7ffdedfa271b886af6

Contents?: true

Size: 811 Bytes

Versions: 2

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true
module Mobility
=begin

Module loading ActiveRecord-specific classes for Mobility models.

=end
  module ActiveRecord
    require "mobility/active_record/uniqueness_validator"

    class QueryMethod < Module
      def initialize(query_method)
        module_eval <<-EOM, __FILE__, __LINE__ + 1
          def #{query_method}
            all
          end
        EOM
      end
    end

    def self.included(model_class)
      model_class.extend QueryMethod.new(Mobility.query_method)
      unless model_class.const_defined?(:UniquenessValidator)
        model_class.const_set(:UniquenessValidator,
                              Class.new(::Mobility::ActiveRecord::UniquenessValidator))
      end
      model_class.delegate :translated_attribute_names, to: :class
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.5.1 lib/mobility/active_record.rb
mobility-0.5.0 lib/mobility/active_record.rb