Class: RestCore::Builder
- Inherits:
-
Object
- Object
- RestCore::Builder
- Defined in:
- lib/rest-core/builder.rb
Constant Summary
Constants included from RestCore
ASYNC, CLIENT, DRY, FAIL, HIJACK, LOG, PROMISE, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_SOCKET, RESPONSE_STATUS, Simple, TIMER, Universal, VERSION
Instance Attribute Summary
Attributes included from Wrapper
#default_engine, #middles, #wrapped
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(&block) ⇒ Builder
constructor
A new instance of Builder.
- #to_client(*attrs) ⇒ Object
Methods included from Wrapper
included, #members, partial_deep_copy, #run, #to_app, #use
Methods included from RestCore
Constructor Details
#initialize(&block) ⇒ Builder
Returns a new instance of Builder.
41 42 43 44 45 |
# File 'lib/rest-core/builder.rb', line 41 def initialize &block @engine = nil @middles ||= [] instance_eval(&block) if block_given? end |
Class Method Details
.client(*attrs, &block) ⇒ Object
13 14 15 |
# File 'lib/rest-core/builder.rb', line 13 def self.client *attrs, &block new(&block).to_client(*attrs) end |
.default_engine ⇒ Object
9 10 11 |
# File 'lib/rest-core/builder.rb', line 9 def self.default_engine @default_engine ||= RestCore::HttpClient end |
Instance Method Details
#to_client(*attrs) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rest-core/builder.rb', line 17 def to_client *attrs fields = members + attrs struct = if fields.empty? Struct.new(nil) else Struct.new(*fields.uniq) end client = Class.new(struct) client.const_set('Struct', struct) client.send(:include, Client) class << client attr_reader :builder attr_accessor :pool_size, :pool_idle_time def thread_pool RestCore::ThreadPool[self] end end client.instance_variable_set(:@builder, self) client.instance_variable_set(:@pool_size, 0) # default to no pool client.instance_variable_set(:@pool_idle_time, 60) # default to 60 seconds client end |