Class: RestCore::Builder

Inherits:
Object
  • Object
show all
Includes:
RestCore, Wrapper
Defined in:
lib/rest-core/builder.rb

Constant Summary

Constant Summary

Constants included from RestCore

ASYNC, DRY, FAIL, FUTURE, LOG, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_STATUS, RootFiber, TIMER, Universal, VERSION

Instance Attribute Summary

Attributes included from Wrapper

#default_engine, #middles, #wrapped

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Wrapper

included, #members, partial_deep_copy, #run, #to_app, #use

Methods included from RestCore

eagerload

Constructor Details

- (Builder) initialize(&block)

A new instance of Builder



32
33
34
35
# File 'lib/rest-core/builder.rb', line 32

def initialize &block
  @middles ||= []
  instance_eval(&block) if block_given?
end

Class Method Details

+ (Object) client(*attrs, &block)



13
14
15
# File 'lib/rest-core/builder.rb', line 13

def self.client *attrs, &block
  new(&block).to_client(*attrs)
end

+ (Object) default_engine



9
10
11
# File 'lib/rest-core/builder.rb', line 9

def self.default_engine
  @default_engine ||= RestCore::Auto
end

Instance Method Details

- (Object) to_client(*attrs)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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)
           end
  client = Class.new(struct)
  client.const_set('Struct', struct)
  client.send(:include, Client)
  class << client; attr_reader :builder; end
  client.instance_variable_set(:@builder, self)
  client
end