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.

Defined Under Namespace

Classes: QueryMethods

Backend Accessors collapse

Methods included from Column

#column, column_name_for, included

Methods included from Mobility::Backend::OrmDelegator

#for

Methods included from Mobility::Backends::Sequel

included, #setup_query_methods

Instance Method Details

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

Yields locales available for this attribute.

Yield Parameters:

  • Locale (Symbol)


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

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

#read(locale, _ = {}) ⇒ Object

Gets the translated value for provided locale from configured backend.

Parameters:

  • locale (Symbol)

    Locale to read

Returns:

  • (Object)

    Value of translation



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

def read(locale, _ = {})
  column = column(locale)
  model[column] if model.columns.include?(column)
end

#write(locale, value, _ = {}) ⇒ 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



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

def write(locale, value, _ = {})
  column = column(locale)
  model[column] = value if model.columns.include?(column)
end