Class: I18n::Backend::KeyValue::SubtreeProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/backend/key_value.rb

Instance Method Summary collapse

Constructor Details

#initialize(master_key, store) ⇒ SubtreeProxy

Returns a new instance of SubtreeProxy



135
136
137
138
139
# File 'lib/i18n/backend/key_value.rb', line 135

def initialize(master_key, store)
  @master_key = master_key
  @store = store
  @subtree = nil
end

Instance Method Details

#[](key) ⇒ Object



145
146
147
148
149
150
151
152
153
154
# File 'lib/i18n/backend/key_value.rb', line 145

def [](key)
  unless @subtree && value = @subtree[key]
    value = @store["#{@master_key}.#{key}"]
    if value
      value = JSON.decode(value)
      (@subtree ||= {})[key] = value
    end
  end
  value
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/i18n/backend/key_value.rb', line 141

def has_key?(key)
  @subtree && @subtree.has_key?(key) || self[key]
end

#inspectObject



169
170
171
# File 'lib/i18n/backend/key_value.rb', line 169

def inspect
  @subtree.inspect
end

#instance_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/i18n/backend/key_value.rb', line 161

def instance_of?(klass)
  Hash == klass || super
end

#is_a?(klass) ⇒ Boolean Also known as: kind_of?

Returns:

  • (Boolean)


156
157
158
# File 'lib/i18n/backend/key_value.rb', line 156

def is_a?(klass)
  Hash == klass || super
end

#nil?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/i18n/backend/key_value.rb', line 165

def nil?
  @subtree.nil?
end