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, Policy, Query, Role, Service, Session, Status, Token
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.
-
#configuration ⇒ Diplomat::Configuration
Get client configuration or global one if not specified via initialize.
-
#initialize(api_connection = nil, configuration: 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, configuration: nil) ⇒ RestClient
Initialize the fadaray connection
12 13 14 15 |
# File 'lib/diplomat/rest_client.rb', line 12 def initialize(api_connection = nil, configuration: nil) @configuration = configuration start_connection api_connection end |
Class Method Details
.access_method?(meth_id) ⇒ Boolean
44 45 46 |
# File 'lib/diplomat/rest_client.rb', line 44 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”.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/diplomat/rest_client.rb', line 53 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 => e raise NoMethodError, e end end end |
.respond_to?(meth_id, with_private = false) ⇒ Boolean
Make ‘respond_to?` aware of method short-cuts.
71 72 73 |
# File 'lib/diplomat/rest_client.rb', line 71 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.
80 81 82 |
# File 'lib/diplomat/rest_client.rb', line 80 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.
34 35 36 37 38 39 40 41 |
# File 'lib/diplomat/rest_client.rb', line 34 def concat_url(parts) parts.reject!(&:empty?) if parts.length > 1 parts.first + '?' + parts.drop(1).join('&') else parts.first end end |
#configuration ⇒ Diplomat::Configuration
Get client configuration or global one if not specified via initialize.
19 20 21 |
# File 'lib/diplomat/rest_client.rb', line 19 def configuration @configuration || ::Diplomat.configuration end |
#use_named_parameter(name, value) ⇒ Array
Format url parameters into strings correctly
27 28 29 |
# File 'lib/diplomat/rest_client.rb', line 27 def use_named_parameter(name, value) value ? ["#{name}=#{value}"] : [] end |