class Locomotive::Steam::Models::I18nField
Attributes
__translations__[R]
name[R]
to_hash[R]
translations[R]
Public Class Methods
new(name, translations)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 12 def initialize(name, translations) @name = name self.translations = translations end
Public Instance Methods
[](locale)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 22 def [](locale) @translations[locale] end
[]=(locale, value)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 26 def []=(locale, value) @translations[locale] = value end
apply() { |default| ... }
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 49 def apply(&block) if default @translations = Hash.new(yield(default)) else each do |l, _value| self[l] = block.arity == 2 ? yield(_value, l) : yield(_value) end end self end
blank?()
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 42 def blank? @translations.default.blank? && ( @translations.blank? || @translations.values.all? { |v| v.blank? } ) end
duplicate(new_name)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 60 def duplicate(new_name) self.class.new(new_name, self.translations) end
each(&block)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 38 def each(&block) @translations.each(&block) end
initialize_copy(field)
click to toggle source
Calls superclass method
# File lib/locomotive/steam/models/i18n_field.rb, line 17 def initialize_copy(field) super self.translations = field.translations.dup end
serialize(attributes)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 68 def serialize(attributes) attributes[@name] = @translations end
to_json()
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 72 def to_json to_hash.to_json end
translations=(translations)
click to toggle source
# File lib/locomotive/steam/models/i18n_field.rb, line 30 def translations=(translations) @translations = (if translations.respond_to?(:fetch) translations else Hash.new(translations) end).with_indifferent_access end