class Jess::Resource
Wraps a JSON object that is returned from the JSS API. The underlying raw JSON is available via `_json`. Properties of the JSON can be accessed via `method_missing`, so that a Resource
behaves like a typical Ruby object. Accessing a non-existent JSON property will raise `NoMethodError`.
Attributes
_json[R]
Public Class Methods
new(json)
click to toggle source
# File lib/jess/resource.rb, line 10 def initialize(json) @_json = json.freeze end
Public Instance Methods
to_hash()
click to toggle source
# File lib/jess/resource.rb, line 14 def to_hash _json end
Private Instance Methods
_as_resource(json)
click to toggle source
# File lib/jess/resource.rb, line 32 def _as_resource(json) case json when Hash Resource.new(json) when Array json.map { |j| _as_resource(j) }.freeze else json.freeze end end
method_missing(symbol, *args)
click to toggle source
Calls superclass method
# File lib/jess/resource.rb, line 20 def method_missing(symbol, *args) if _json.key?(symbol.to_s) _as_resource(_json.public_send(:[], symbol.to_s, *args)) else super end end
respond_to_missing?(symbol, include_all)
click to toggle source
Calls superclass method
# File lib/jess/resource.rb, line 28 def respond_to_missing?(symbol, include_all) super || _json.key?(symbol.to_s) end