module Mobility::Backends::Sequel::ClassMethods

Public Instance Methods

[](name, locale) click to toggle source

@param [Symbol] name Attribute name @param [Symbol] locale Locale

# File lib/mobility/backends/sequel.rb, line 15
def [](name, locale)
  build_op(name.to_s, locale)
end
build_op(_attr, _locale) click to toggle source

@param [String] _attr Attribute name @param [Symbol] _locale Locale @return Op for this translated attribute

# File lib/mobility/backends/sequel.rb, line 22
def build_op(_attr, _locale)
  raise NotImplementedError
end
define_column_changes(mod, attributes, column_affix: "%s") click to toggle source

Forces Sequel to notice changes when Mobility setter method is called. TODO: Find a better way to do this.

Calls superclass method
# File lib/mobility/backends/sequel.rb, line 37
def define_column_changes(mod, attributes, column_affix: "%s")
  mod.class_eval do
    attributes.each do |attribute|
      define_method "#{attribute}=" do |value, **options|
        if !options[:super] && send(attribute) != value
          locale = options[:locale] || Mobility.locale
          column = (column_affix % attribute).to_sym
          attribute_with_locale = :"#{attribute}_#{Mobility.normalize_locale(locale)}"
          @changed_columns = changed_columns | [column, attribute.to_sym, attribute_with_locale]
        end
        super(value, **options)
      end
    end
  end
end
define_hash_initializer(mod, columns) click to toggle source

Initialize column value(s) by default to a hash. TODO: Find a better way to do this.

# File lib/mobility/backends/sequel.rb, line 55
        def define_hash_initializer(mod, columns)
          mod.class_eval do
            class_eval <<-EOM, __FILE__, __LINE__ + 1
              def initialize_set(values)
                #{columns.map { |c| "self[:#{c}] = {}" }.join(';')}
                super
              end
            EOM
          end
        end
prepare_dataset(dataset, _predicate, _locale) click to toggle source

@param [Sequel::Dataset] dataset Dataset to prepare @param [Object] predicate Predicate @param [Symbol] locale Locale @return [Sequel::Dataset] Prepared dataset

# File lib/mobility/backends/sequel.rb, line 30
def prepare_dataset(dataset, _predicate, _locale)
  dataset
end