Sha256: 728bb2a6db7fff0f322a3e32251fbcbe1970ddf277349c0acce15a6fa3449977

Contents?: true

Size: 763 Bytes

Versions: 7

Compression:

Stored size: 763 Bytes

Contents

require 'rest-core/client'
require 'rest-core/wrapper'

class RestCore::Builder
  include RestCore
  include Wrapper

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

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

  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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rest-core-2.1.1 lib/rest-core/builder.rb
rest-core-2.1.0 lib/rest-core/builder.rb
rest-core-2.0.4 lib/rest-core/builder.rb
rest-core-2.0.3 lib/rest-core/builder.rb
rest-core-2.0.2 lib/rest-core/builder.rb
rest-core-2.0.1 lib/rest-core/builder.rb
rest-core-2.0.0 lib/rest-core/builder.rb