Sha256: a90e993b15f105405f1be530f75cd9e02be7f4aa09b6dc8b554fe72e4cb65d5e

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

require 'leadlight/basic_converter'

module Leadlight
  module ServiceClassMethods
    fattr(:tints) { default_tints }

    def url(new_url=:none)
      if new_url == :none
        @url ||= Addressable::URI.parse('http://example.com')
      else
        @url = Addressable::URI.parse(new_url)
      end
    end

    def session(options={})
      sessions[options]
    end

    def sessions
      @sessions ||= Hash.new{|h,k|
        h[k] = new(k)
      }
    end

    def connection_stack
      @connection_stack ||= ->(builder){}
    end

    def default_tints
      [
       EnumerableRepresentation::Tint
      ]
    end

    def request_class
      @request_class ||= Class.new(Request)
    end

    private

    def tint(name, options={}, &block)
      self.tints << Tint.new(name, options, &block)
    end

    # Declare a new type mapping. Either pass a converter ("type")
    # class, or pass a block which defines #decode and #encode
    # methods.
    def type_mapping(enctype_patterns,
                     object_patterns,
                     converter_class=make_converter_class,
                     &converter_definition)
      converter_class.module_eval(&converter_definition) if converter_definition
      on_init do
        type_map.add(enctype_patterns, object_patterns, converter_class.new(codec))
      end
    end

    def build_connection(&block)
      @connection_stack = block
    end

    def http_adapter(*http_adapter_options)
      if http_adapter_options.empty?
        @http_adapter ||= [:net_http]
      else
        @http_adapter = http_adapter_options
      end
    end

    def make_converter_class
      Class.new do
        include BasicConverter
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
leadlight-0.1.0 lib/leadlight/service_class_methods.rb
leadlight-0.0.7 lib/leadlight/service_class_methods.rb
leadlight-0.0.6 lib/leadlight/service_class_methods.rb