class Spaceship::Base::DataHash

Public Class Methods

new(hash) click to toggle source
# File spaceship/lib/spaceship/base.rb, line 27
def initialize(hash)
  @hash = hash || {}
end

Public Instance Methods

[](*keys)
Alias for: get
delete(key) click to toggle source
# File spaceship/lib/spaceship/base.rb, line 48
def delete(key)
  @hash.delete(key)
end
each(&block) click to toggle source
# File spaceship/lib/spaceship/base.rb, line 61
def each(&block)
  @hash.each(&block)
end
get(*keys) click to toggle source
# File spaceship/lib/spaceship/base.rb, line 35
def get(*keys)
  lookup(keys)
end
Also aliased as: []
key?(key) click to toggle source
# File spaceship/lib/spaceship/base.rb, line 31
def key?(key)
  @hash.key?(key)
end
lookup(keys) click to toggle 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
set(keys, value) click to toggle 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
to_h() click to toggle source
# File spaceship/lib/spaceship/base.rb, line 74
def to_h
  @hash.dup
end
to_json(*a) click to toggle 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