Class: Nagios::API::Resource
- Inherits:
-
Object
- Object
- Nagios::API::Resource
- Defined in:
- lib/nagios/api/resource.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Resource
constructor
A new instance of Resource.
- #method_missing(meth, *args, &block) ⇒ Object
- #to_hash(options = {}) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 |
# File 'lib/nagios/api/resource.rb', line 6 def initialize(args = {}) @api_client = args.delete(:api_client) @attributes = {} self.attributes = args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nagios/api/resource.rb', line 19 def method_missing(meth, *args, &block) if meth.to_s =~ /^(.+)=$/ @attributes[$1.to_sym] = args[0] elsif @attributes.has_key?(meth) @attributes[meth] else super # You *must* call super if you don't handle the # method, otherwise you'll mess up Ruby's method # lookup. end end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
3 4 5 |
# File 'lib/nagios/api/resource.rb', line 3 def api_client @api_client end |
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/nagios/api/resource.rb', line 4 def attributes @attributes end |
Instance Method Details
#to_hash(options = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/nagios/api/resource.rb', line 31 def to_hash( = {}) hash = attributes hash.reject! { |key, value| [:except].include?(key.to_sym) || [:except].include?(key.to_s) } if [:except] hash.reject! { |key, value| ![:only].include?(key.to_sym) && ![:only].include?(key.to_s) } if [:only] hash end |