Sha256: 0d02f70a3c464b7fbcaca4ba95e6bc48c8f96d79f87c4fdcb1683b64995f27cd

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module Mobility
  module Backend
=begin

Implements the {Mobility::Backend::Column} backend for ActiveRecord models.

@note This backend disables the +accessor_locales+ option, which would
  otherwise interfere with column methods.

@example
  class Post < ActiveRecord::Base
    translates :title, backend: :column
  end

  Mobility.locale = :en
  post = Post.create(title: "foo")
  post.title
  #=> "foo"
  post.title_en
  #=> "foo"
=end
    class ActiveRecord::Column
      include Backend
      include Mobility::Backend::Column

      autoload :QueryMethods, 'mobility/backend/active_record/column/query_methods'

      # @!group Backend Accessors
      # @!macro backend_reader
      # @!method read(locale, **options)

      # @!group Backend Accessors
      # @!macro backend_writer
      # @!method write(locale, value, **options)

      # @!group Backend Configuration
      def self.configure!(options)
        options[:locale_accessors] = false
      end
      # @!endgroup

      setup do |attributes, options|
        mod = Module.new do
          define_method :i18n do
            @mobility_scope ||= super().extending(QueryMethods.new(attributes, options))
          end
        end
        extend mod
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mobility-0.1.5 lib/mobility/backend/active_record/column.rb
mobility-0.1.4 lib/mobility/backend/active_record/column.rb
mobility-0.1.3 lib/mobility/backend/active_record/column.rb
mobility-0.1.2 lib/mobility/backend/active_record/column.rb
mobility-0.1.1 lib/mobility/backend/active_record/column.rb
mobility-0.1.0 lib/mobility/backend/active_record/column.rb