class Mumukit::Service::JsonWrapper

Attributes

raw[RW]

Public Class Methods

new(json) click to toggle source
# File lib/mumukit/service/document.rb, line 6
def initialize(json)
  @raw = json.to_h.symbolize_keys
end

Public Instance Methods

[]=(key, value) click to toggle source
# File lib/mumukit/service/document.rb, line 24
def []=(key, value)
  @raw[key.to_sym] = value
  @json = nil
end
as_json(options={}) click to toggle source
# File lib/mumukit/service/document.rb, line 10
def as_json(options={})
  json.as_json(options)
end
defaults() click to toggle source
# File lib/mumukit/service/document.rb, line 33
def defaults
  {}
end
errors() click to toggle source
# File lib/mumukit/service/document.rb, line 37
def errors
  []
end
json() click to toggle source
# File lib/mumukit/service/document.rb, line 46
def json
  @json ||= defaults.
      merge(@raw).
      merge(transforms(@raw))
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/mumukit/service/document.rb, line 14
def method_missing(name, *args)
  if args.size == 0
    self[name]
  elsif args.size == 1
    self[name[0..-2]] = args.first
  else
    super
  end
end
transforms(original) click to toggle source
# File lib/mumukit/service/document.rb, line 29
def transforms(original)
  {}
end
validate!() click to toggle source
# File lib/mumukit/service/document.rb, line 41
def validate!
  e = errors
  raise DocumentValidationError, e.join(', ') unless e.empty?
end