Class: Mobility::Backends::Sequel::Column

Inherits:
Object
  • Object
show all
Includes:
Column, Mobility::Backends::Sequel
Defined in:
lib/mobility/backends/sequel/column.rb

Overview

Implements the Column backend for Sequel models.

Backend Accessors collapse

Methods included from Column

#column, column_name_for

Methods included from Mobility::Backends::Sequel

included

Class Method Details

.build_op(attr, locale) ⇒ Object



35
36
37
38
# File 'lib/mobility/backends/sequel/column.rb', line 35

def self.build_op(attr, locale)
  ::Sequel::SQL::QualifiedIdentifier.new(model_class.table_name,
                                         Column.column_name_for(attr, locale))
end

Instance Method Details

#each_locale {|Locale| ... } ⇒ Object

Yields locales available for this attribute.

Yield Parameters:

  • Locale (Symbol)


31
32
33
# File 'lib/mobility/backends/sequel/column.rb', line 31

def each_locale
  available_locales.each { |l| yield(l) if present?(l) }
end

#read(locale, _options = nil) ⇒ Object

Gets the translated value for provided locale from configured backend.

Parameters:

  • locale (Symbol)

    Locale to read

Returns:

  • (Object)

    Value of translation



18
19
20
21
# File 'lib/mobility/backends/sequel/column.rb', line 18

def read(locale, _options = nil)
  column = column(locale)
  model[column] if model.columns.include?(column)
end

#write(locale, value, _options = nil) ⇒ Object

Updates translation for provided locale without calling backend’s methods to persist the changes.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (Object)

    Value to write

Returns:

  • (Object)

    Updated value



25
26
27
28
# File 'lib/mobility/backends/sequel/column.rb', line 25

def write(locale, value, _options = nil)
  column = column(locale)
  model[column] = value if model.columns.include?(column)
end