class Spaceship::Base::DataHash

Public Class Methods

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

Public Instance Methods

[](*keys)
Alias for: get
get(*keys) click to toggle source
# File lib/spaceship/base.rb, line 27
def get(*keys)
  lookup(keys)
end
Also aliased as: []
lookup(keys) click to toggle source
# File lib/spaceship/base.rb, line 40
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 lib/spaceship/base.rb, line 33
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_json(*a) click to toggle source
# File lib/spaceship/base.rb, line 49
def to_json(*a)
  h = @hash.dup
  h.delete(:application)
  h.to_json(*a)
end