Sha256: 66b9160d2b43b64ddb2026b81a2c642dc3d0bb7a9a36b636ecc133b786012037

Contents?: true

Size: 804 Bytes

Versions: 11

Compression:

Stored size: 804 Bytes

Contents

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

class RestCore::Builder
  include RestCore
  include Wrapper

  class << self
    attr_writer :default_app
  end
  def self.default_app
    @default_app ||= RestClient
  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

11 entries across 11 versions & 1 rubygems

Version Path
rest-core-1.0.1 lib/rest-core/builder.rb
rest-core-1.0.0 lib/rest-core/builder.rb
rest-core-0.8.2 lib/rest-core/builder.rb
rest-core-0.8.1 lib/rest-core/builder.rb
rest-core-0.8.0 lib/rest-core/builder.rb
rest-core-0.7.2 lib/rest-core/builder.rb
rest-core-0.7.0 lib/rest-core/builder.rb
rest-core-0.4.0 lib/rest-core/builder.rb
rest-core-0.4.0.pre.2 lib/rest-core/builder.rb
rest-core-0.4.0.pre.1 lib/rest-core/builder.rb
rest-core-0.4.0.pre.0 lib/rest-core/builder.rb