Class: Mobility::Backends::ActiveRecord::Serialized

Inherits:
Object
  • Object
show all
Includes:
Mobility::Backends::ActiveRecord, HashValued
Defined in:
lib/mobility/backends/active_record/serialized.rb

Overview

Implements Serialized backend for ActiveRecord models.

Examples:

Define attribute with serialized backend

class Post < ActiveRecord::Base
  translates :title, backend: :serialized, format: :yaml
end

Read and write attribute translations

post = Post.create(title: "foo")
post.title
#=> "foo"
Mobility.locale = :ja
post.title = "あああ"
post.save
post.read_attribute(:title)      # get serialized value
#=> {:en=>"foo", :ja=>"あああ"}

Defined Under Namespace

Classes: QueryMethods

Backend Configuration collapse

Cache Methods collapse

Methods included from HashValued

#each_locale, #read, #write

Methods included from Mobility::Backends::ActiveRecord

included, #setup_query_methods

Class Method Details

.configure(options) ⇒ Object

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • format (Symbol) — default: :yaml

    Serialization format

Raises:

  • (ArgumentError)

    if a format other than :yaml or :json is passed in



37
38
39
# File 'lib/mobility/backends/active_record/serialized.rb', line 37

def self.configure(options)
  Serialized.configure(options)
end

Instance Method Details

#translationsHash

Returns column value as a hash

Returns:

  • (Hash)


52
53
54
# File 'lib/mobility/backends/active_record/serialized.rb', line 52

def translations
  model.read_attribute(attribute)
end