class Backup::Backblaze::HashWrap

Intended as a quick-n-dirty way to deep-wrap json objects. If it doesn't work for you, rather than scope-creeping this consider: Hash, OpenStruct, a class, etc.

Public Class Methods

from_json(json) click to toggle source

really a convenience method

# File lib/backup/backblaze/hash_wrap.rb, line 40
def self.from_json json
  new JSON.parse json
end
new( hash ) click to toggle source
# File lib/backup/backblaze/hash_wrap.rb, line 8
def initialize( hash )
  @hash = hash
end

Public Instance Methods

method_missing(meth, *args, &blk) click to toggle source
Calls superclass method
# File lib/backup/backblaze/hash_wrap.rb, line 12
def method_missing(meth, *args, &blk)
  value = @hash.fetch meth.to_s do |_key|
    @hash.fetch meth do |_key|
      super
    end
  end
  __wrap value
end
to_h() click to toggle source
# File lib/backup/backblaze/hash_wrap.rb, line 34
def to_h
  # no, you can't have a copy of this hash to mess with
  @hash.dup
end

Private Instance Methods

__wrap(value) click to toggle source
# File lib/backup/backblaze/hash_wrap.rb, line 21
        def __wrap value
  case value
  when Hash
    self.class.new value
  when Array
    value.map do |item|
      __wrap item
    end
  else
    value
  end
end