Class: Diplomat::RestClient
- Inherits:
-
Object
- Object
- Diplomat::RestClient
- Defined in:
- lib/diplomat/rest_client.rb
Overview
Base class for interacting with the Consul RESTful API
Direct Known Subclasses
Acl, Agent, Check, Datacenter, Event, Health, Kv, Lock, Maintenance, Members, Node, Nodes, Query, Service, Session, Status
Class Method Summary collapse
- .access_method?(meth_id) ⇒ Boolean
-
.method_missing(meth_id, *args) ⇒ Boolean
Allow certain methods to be accessed without defining “new”.
-
.respond_to?(meth_id, with_private = false) ⇒ Boolean
Make ‘respond_to?` aware of method short-cuts.
-
.respond_to_missing?(meth_id, with_private = false) ⇒ Boolean
Make ‘respond_to_missing` aware of method short-cuts.
Instance Method Summary collapse
-
#concat_url(parts) ⇒ String
Assemble a url from an array of parts.
-
#initialize(api_connection = nil) ⇒ RestClient
constructor
Initialize the fadaray connection.
-
#use_named_parameter(name, value) ⇒ Array
Format url parameters into strings correctly.
Constructor Details
#initialize(api_connection = nil) ⇒ RestClient
Initialize the fadaray connection
8 9 10 |
# File 'lib/diplomat/rest_client.rb', line 8 def initialize(api_connection = nil) start_connection api_connection end |
Class Method Details
.access_method?(meth_id) ⇒ Boolean
32 33 34 |
# File 'lib/diplomat/rest_client.rb', line 32 def access_method?(meth_id) @access_methods.include? meth_id end |
.method_missing(meth_id, *args) ⇒ Boolean
Allow certain methods to be accessed without defining “new”.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diplomat/rest_client.rb', line 41 def method_missing(meth_id, *args) if access_method?(meth_id) new.send(meth_id, *args) else # See https://bugs.ruby-lang.org/issues/10969 begin super rescue NameError => err raise NoMethodError, err end end end |
.respond_to?(meth_id, with_private = false) ⇒ Boolean
Make ‘respond_to?` aware of method short-cuts.
59 60 61 |
# File 'lib/diplomat/rest_client.rb', line 59 def respond_to?(meth_id, with_private = false) access_method?(meth_id) || super end |
.respond_to_missing?(meth_id, with_private = false) ⇒ Boolean
Make ‘respond_to_missing` aware of method short-cuts. This is needed for #method to work on these, which is helpful for testing purposes.
68 69 70 |
# File 'lib/diplomat/rest_client.rb', line 68 def respond_to_missing?(meth_id, with_private = false) access_method?(meth_id) || super end |
Instance Method Details
#concat_url(parts) ⇒ String
Assemble a url from an array of parts.
23 24 25 26 27 28 29 |
# File 'lib/diplomat/rest_client.rb', line 23 def concat_url(parts) if parts.length > 1 parts.first + '?' + parts.drop(1).join('&') else parts.first end end |
#use_named_parameter(name, value) ⇒ Array
Format url parameters into strings correctly
16 17 18 |
# File 'lib/diplomat/rest_client.rb', line 16 def use_named_parameter(name, value) value ? ["#{name}=#{value}"] : [] end |