class Spaceship::Base::DataHash
Public Class Methods
Source
# File spaceship/lib/spaceship/base.rb, line 27 def initialize(hash) @hash = hash || {} end
Public Instance Methods
Source
# File spaceship/lib/spaceship/base.rb, line 48 def delete(key) @hash.delete(key) end
Source
# File spaceship/lib/spaceship/base.rb, line 61 def each(&block) @hash.each(&block) end
Source
# File spaceship/lib/spaceship/base.rb, line 35 def get(*keys) lookup(keys) end
Also aliased as: []
Source
# File spaceship/lib/spaceship/base.rb, line 52 def lookup(keys) head, *tail = *keys if tail.empty? @hash[head] else DataHash.new(@hash[head]).lookup(tail) end end
Source
# File spaceship/lib/spaceship/base.rb, line 41 def set(keys, value) raise "'keys' must be an array, got #{keys.class} instead" unless keys.kind_of?(Array) last = keys.pop ref = lookup(keys) || @hash ref[last] = value end
Source
# File spaceship/lib/spaceship/base.rb, line 65 def to_json(*a) h = @hash.dup h.delete(:application) h.to_json(*a) rescue JSON::GeneratorError => e puts("Failed to jsonify #{h} (#{a})") if Spaceship::Globals.verbose? raise e end