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, Autopilot, 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
14 15 16 17 |
# File 'lib/diplomat/rest_client.rb', line 14 def initialize(api_connection = nil, configuration: nil) @configuration = configuration start_connection api_connection end |
Class Method Details
.access_method?(meth_id) ⇒ Boolean
46 47 48 |
# File 'lib/diplomat/rest_client.rb', line 46 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”.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/diplomat/rest_client.rb', line 55 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.
73 74 75 |
# File 'lib/diplomat/rest_client.rb', line 73 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.
82 83 84 |
# File 'lib/diplomat/rest_client.rb', line 82 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.
36 37 38 39 40 41 42 43 |
# File 'lib/diplomat/rest_client.rb', line 36 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.
21 22 23 |
# File 'lib/diplomat/rest_client.rb', line 21 def configuration @configuration || ::Diplomat.configuration end |
#use_named_parameter(name, value) ⇒ Array
Format url parameters into strings correctly
29 30 31 |
# File 'lib/diplomat/rest_client.rb', line 29 def use_named_parameter(name, value) value ? ["#{name}=#{value}"] : [] end |