Class: Seahorse::Client::Base
- Inherits:
-
Object
- Object
- Seahorse::Client::Base
- Includes:
- HandlerBuilder
- Defined in:
- lib/seahorse/client/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #config ⇒ Configuration<Struct> readonly
- #handlers ⇒ HandlerList readonly
Class Method Summary collapse
-
.add_plugin(plugin) ⇒ void
Registers a plugin with this client.
- .api ⇒ Model::Api
- .clear_plugins ⇒ void
- .define(options = {}) ⇒ Class<Client::Base> (also: extend)
- .new(options = {}) ⇒ Object
-
.plugins ⇒ Array<Plugin>
Returns the list of registered plugins for this Client.
- .remove_plugin(plugin) ⇒ void
- .set_api(api) ⇒ Model::Api
- .set_plugins(plugins) ⇒ void
Instance Method Summary collapse
-
#build_request(operation_name, params = {}) ⇒ Request
Builds and returns a Request for the named operation.
-
#initialize(plugins, options) ⇒ Base
constructor
private
A new instance of Base.
- #inspect ⇒ Object private
- #method_missing(method_name, *args, &block) ⇒ Object private
- #operation(name) ⇒ Model::Operation
-
#operation_names ⇒ Array<Symbol>
Returns a list of valid request operation names.
- #respond_to?(method_name, *args) ⇒ Boolean private
Methods included from HandlerBuilder
#handle, #handle_request, #handle_response, #handler_for, #new_handler
Constructor Details
#initialize(plugins, options) ⇒ Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Base.
19 20 21 22 23 |
# File 'lib/seahorse/client/base.rb', line 19 def initialize(plugins, ) @config = build_config(plugins, ) @handlers = build_handler_list(plugins) after_initialize(plugins) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 72 73 74 75 |
# File 'lib/seahorse/client/base.rb', line 69 def method_missing(method_name, *args, &block) if request_method?(method_name) make_request(method_name, *args, &block) else super end end |
Instance Attribute Details
#config ⇒ Configuration<Struct> (readonly)
26 27 28 |
# File 'lib/seahorse/client/base.rb', line 26 def config @config end |
#handlers ⇒ HandlerList (readonly)
29 30 31 |
# File 'lib/seahorse/client/base.rb', line 29 def handlers @handlers end |
Class Method Details
.add_plugin(plugin) ⇒ void
This method returns an undefined value.
Registers a plugin with this client.
161 162 163 |
# File 'lib/seahorse/client/base.rb', line 161 def add_plugin(plugin) @plugins.add(plugin) end |
.api ⇒ Model::Api
205 206 207 |
# File 'lib/seahorse/client/base.rb', line 205 def api @api ||= Model::Api.new end |
.clear_plugins ⇒ void
This method returns an undefined value.
179 180 181 |
# File 'lib/seahorse/client/base.rb', line 179 def clear_plugins @plugins.set([]) end |
.define(options = {}) ⇒ Class<Client::Base> Also known as: extend
223 224 225 226 227 228 229 230 |
# File 'lib/seahorse/client/base.rb', line 223 def define( = {}) subclass = Class.new(self) subclass.set_api([:api] || api) Array([:plugins]).each do |plugin| subclass.add_plugin(plugin) end subclass end |
.new(options = {}) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/seahorse/client/base.rb', line 131 def new( = {}) plugins = build_plugins = .dup before_initialize(plugins, ) client = allocate client.send(:initialize, plugins, ) client end |
.plugins ⇒ Array<Plugin>
Returns the list of registered plugins for this Client. Plugins are inherited from the client super class when the client is defined.
200 201 202 |
# File 'lib/seahorse/client/base.rb', line 200 def plugins Array(@plugins).freeze end |
.remove_plugin(plugin) ⇒ void
This method returns an undefined value.
170 171 172 |
# File 'lib/seahorse/client/base.rb', line 170 def remove_plugin(plugin) @plugins.remove(plugin) end |
.set_api(api) ⇒ Model::Api
211 212 213 214 215 216 217 |
# File 'lib/seahorse/client/base.rb', line 211 def set_api(api) if api.is_a?(Hash) @api = Model::Api.new(api) else @api = api end end |
.set_plugins(plugins) ⇒ void
This method returns an undefined value.
189 190 191 |
# File 'lib/seahorse/client/base.rb', line 189 def set_plugins(plugins) @plugins.set(plugins) end |
Instance Method Details
#build_request(operation_name, params = {}) ⇒ Request
Builds and returns a Request for the named operation. The request will not have been sent.
35 36 37 38 39 |
# File 'lib/seahorse/client/base.rb', line 35 def build_request(operation_name, params = {}) Request.new( @handlers.for(operation_name), context_for(operation_name, params)) end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/seahorse/client/base.rb', line 48 def inspect "#<#{self.class.name}>" end |
#operation(name) ⇒ Model::Operation
43 44 45 |
# File 'lib/seahorse/client/base.rb', line 43 def operation(name) config.api.operation(name) end |
#operation_names ⇒ Array<Symbol>
Returns a list of valid request operation names. These are valid arguments to #build_request and are also valid methods.
55 56 57 |
# File 'lib/seahorse/client/base.rb', line 55 def operation_names self.class.api.operation_names end |
#respond_to?(method_name, *args) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 |
# File 'lib/seahorse/client/base.rb', line 60 def respond_to?(method_name, *args) if request_method?(method_name) true else super end end |