Class: CoachClient::Resource
- Inherits:
-
Object
- Object
- CoachClient::Resource
- Defined in:
- lib/coach_client/resource.rb
Overview
A resource of the CyberCoach service.
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#exist?(username: nil, password: nil) ⇒ Boolean
Returns whether the resource exists on the CyberCoach service.
-
#initialize(client) ⇒ CoachClient::Resource
constructor
Creates a new resource.
-
#to_h ⇒ Hash
Returns the hash representation of the resource.
Constructor Details
#initialize(client) ⇒ CoachClient::Resource
Creates a new resource.
11 12 13 |
# File 'lib/coach_client/resource.rb', line 11 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ CoachClient::Client
5 6 7 |
# File 'lib/coach_client/resource.rb', line 5 def client @client end |
Instance Method Details
#exist?(username: nil, password: nil) ⇒ Boolean
Returns whether the resource exists on the CyberCoach service.
20 21 22 23 24 25 26 27 |
# File 'lib/coach_client/resource.rb', line 20 def exist?(username: nil, password: nil) begin CoachClient::Request.get(url, username: username, password: password) true rescue CoachClient::NotFound false end end |
#to_h ⇒ Hash
Returns the hash representation of the resource.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/coach_client/resource.rb', line 32 def to_h hash = {} instance_variables.each do |var| next if var.to_s == '@client' value = instance_variable_get(var) hash[var.to_s.delete('@').to_sym] = if value && value.respond_to?(:to_h) && !value.is_a?(Array) value.to_h else value end end hash end |