Class: Jess::Resource
- Inherits:
-
Object
- Object
- Jess::Resource
- Defined in:
- lib/jess/resource.rb
Overview
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`.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_json ⇒ Object
readonly
Returns the value of attribute _json.
Instance Method Summary collapse
-
#initialize(json) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(json) ⇒ Resource
Returns a new instance of Resource.
10 11 12 |
# File 'lib/jess/resource.rb', line 10 def initialize(json) @_json = json.freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object (private)
16 17 18 19 20 21 22 |
# File 'lib/jess/resource.rb', line 16 def method_missing(symbol, *args) if _json.key?(symbol.to_s) _as_resource(_json.public_send(:[], symbol.to_s, *args)) else super end end |
Instance Attribute Details
#_json ⇒ Object (readonly)
Returns the value of attribute _json.
8 9 10 |
# File 'lib/jess/resource.rb', line 8 def _json @_json end |