Sha256: d427d6a28d7d735300e0ca000e5cfaf7db6075e585625e465c817e8a3d0d53a5

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

module Mobility
  module Backend
=begin

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

@note This backend disables the +locale_accessors+ option, which would
  otherwise interfere with column methods.
=end
    class Sequel::Column
      include Backend
      include Backend::Column

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

      # @!group Backend Accessors
      # @!macro backend_reader
      def read(locale, **_)
        column = column(locale)
        model.send(column) if model.columns.include?(column)
      end

      # @!group Backend Accessors
      # @!macro backend_writer
      def write(locale, value, **_)
        column = column(locale)
        model.send("#{column}=", value) if model.columns.include?(column)
      end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.1.12 lib/mobility/backend/sequel/column.rb
mobility-0.1.11 lib/mobility/backend/sequel/column.rb