Class: Cukunity::Unity::JSONContainer
- Inherits:
-
Object
- Object
- Cukunity::Unity::JSONContainer
- Includes:
- Cukunity::Utils
- Defined in:
- lib/cukunity/unity/json_container.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #has_key?(key) ⇒ Boolean (also: #has_property?)
-
#initialize(json) ⇒ JSONContainer
constructor
A new instance of JSONContainer.
- #keys ⇒ Object (also: #properties)
-
#method_missing(meth, *args, &block) ⇒ Object
inspect json structure dynamically.
- #to_s ⇒ Object
- #value_of(key) ⇒ Object (also: #[], #property)
Methods included from Cukunity::Utils
#check_timeout, #merge_options, #restrict_options, #to_options, #wait_connectivity
Constructor Details
#initialize(json) ⇒ JSONContainer
Returns a new instance of JSONContainer.
7 8 9 |
# File 'lib/cukunity/unity/json_container.rb', line 7 def initialize(json) @json = json end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
inspect json structure dynamically
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cukunity/unity/json_container.rb', line 31 def method_missing(meth, *args, &block) if json.is_a? Hash meth = meth.to_s return property(meth) if has_property?(meth) if meth[-1..-1] == '?' meth = meth[0...-1] return !!property(meth) if has_property?(meth) end end super end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
5 6 7 |
# File 'lib/cukunity/unity/json_container.rb', line 5 def json @json end |
Instance Method Details
#has_key?(key) ⇒ Boolean Also known as: has_property?
24 25 26 |
# File 'lib/cukunity/unity/json_container.rb', line 24 def has_key?(key) @json.has_key?(key.to_s) end |
#keys ⇒ Object Also known as: properties
18 19 20 |
# File 'lib/cukunity/unity/json_container.rb', line 18 def keys @json.keys end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/cukunity/unity/json_container.rb', line 43 def to_s @json.to_s end |
#value_of(key) ⇒ Object Also known as: [], property
11 12 13 |
# File 'lib/cukunity/unity/json_container.rb', line 11 def value_of(key) @json[key.to_s] end |