class Streetlib::Vault::Content
Attributes
value[RW]
Public Class Methods
new(value = {})
click to toggle source
# File lib/streetlib/vault/content.rb, line 10 def initialize(value = {}) self.value = value end
Public Instance Methods
[](key)
click to toggle source
# File lib/streetlib/vault/content.rb, line 51 def [](key) if value.kind_of?(Array) && key.kind_of?(Numeric) if key >= value.length raise Error.new("Can't access index #{key} on a list of #{value.length} items.") end new_value = value[key] wrap(new_value) else self.send(key) end end
each() { |wrap(item)| ... }
click to toggle source
Calls superclass method
# File lib/streetlib/vault/content.rb, line 28 def each return super unless value.kind_of?(Array) value.each do |item| yield wrap(item) end end
has_key?(key)
click to toggle source
# File lib/streetlib/vault/content.rb, line 44 def has_key?(key) return false unless is_a_dictionary? stringified_key = key.to_s value.keys.include?(stringified_key) end
map() { |wrap(item)| ... }
click to toggle source
Calls superclass method
# File lib/streetlib/vault/content.rb, line 36 def map return super unless value.kind_of?(Array) value.map do |item| yield wrap(item) end end
method_missing(key)
click to toggle source
Calls superclass method
# File lib/streetlib/vault/content.rb, line 14 def method_missing(key) super unless is_a_dictionary? stringified_key = key.to_s unless value.keys.include?(stringified_key) raise Error.new("Key #{stringified_key} doesn't exist at the current path.") end new_value = value[stringified_key] # returning the wrapped sub hash to allow nested chaining wrap(new_value) end
unwrap()
click to toggle source
# File lib/streetlib/vault/content.rb, line 64 def unwrap self.value end
Private Instance Methods
is_a_dictionary?()
click to toggle source
# File lib/streetlib/vault/content.rb, line 73 def is_a_dictionary? return false unless value.respond_to?(:keys) value.keys.respond_to?(:include?) end
wrap(item)
click to toggle source
# File lib/streetlib/vault/content.rb, line 69 def wrap(item) self.class.new(item) end