Class: Mobility::Backend::ActiveRecord::Jsonb

Inherits:
HashValued show all
Defined in:
lib/mobility/backend/active_record/jsonb.rb

Overview

Implements the Jsonb backend for ActiveRecord models.

See Also:

Defined Under Namespace

Classes: QueryMethods

Instance Attribute Summary

Attributes included from Mobility::Backend

#attribute, #model, #options

Backend Accessors collapse

Methods inherited from HashValued

#translations, #write_to_cache?

Methods included from Mobility::Backend

included, #initialize, method_name

Instance Method Details

#read(locale, **options) ⇒ String, ...

Note:

Translation may be string, integer or boolean-valued since value is stored on a JSON hash.

Returns Value of translation.

Parameters:

  • locale (Symbol)

    Locale to read

  • options (Hash)

Returns:

  • (String, Integer, Boolean)

    Value of translation



# File 'lib/mobility/backend/active_record/jsonb.rb', line 15

#write(locale, value, **options) ⇒ String, ...

Note:

Translation may be string, integer or boolean-valued since value is stored on a JSON hash.

Returns Updated value.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (String, Integer, Boolean)

    Value to write

  • options (Hash)

Returns:

  • (String, Integer, Boolean)

    Updated value



33
34
35
36
37
38
39
40
# File 'lib/mobility/backend/active_record/jsonb.rb', line 33

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