class Mobility::Backends::ActiveRecord::Serialized
Implements {Mobility::Backends::Serialized} backend for ActiveRecord
models.
@example Define attribute with serialized backend
class Post < ActiveRecord::Base extend Mobility translates :title, backend: :serialized, format: :yaml end
@example 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=>"あああ"}
Public Class Methods
build_node(attr, _locale)
click to toggle source
@!endgroup
# File lib/mobility/backends/active_record/serialized.rb, line 47 def self.build_node(attr, _locale) raise ArgumentError, "You cannot query on mobility attributes translated with the Serialized backend (#{attr})." end
configure(options)
click to toggle source
@!group Backend
Configuration @param (see Backends::Serialized.configure
) @option (see Backends::Serialized.configure
) @raise (see Backends::Serialized.configure
)
Calls superclass method
# File lib/mobility/backends/active_record/serialized.rb, line 41 def self.configure(options) super Serialized.configure(options) end
valid_keys()
click to toggle source
Calls superclass method
# File lib/mobility/backends/active_record/serialized.rb, line 33 def self.valid_keys super + [:format] end
Public Instance Methods
translations()
click to toggle source
@!group Cache Methods Returns column value as a hash @return [Hash]
# File lib/mobility/backends/active_record/serialized.rb, line 60 def translations model.read_attribute(column_name) end