Sha256: 2e90d0aea8046a4993687cf581195604fde42b2c86bfb7053d162bd4f61f8e8a

Contents?: true

Size: 1.62 KB

Versions: 7

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8

require 'hyperdrive/dsl/resource'

module Hyperdrive
  module DSL
    include Values
    extend self
    attr_reader :config, :resources

    def instance
      @config ||= default_config.dup
      @resources ||= {}
      self
    end

    def instrument(*args)
      @config[:instrumenter] = @config[:instrumenter] || Hyperdrive::Instrumenters::Noop
      @config[:instrumenter].instrument(*args)
    end

    private

    def name(name)
      @config[:name] = name
    end

    def description(description)
      @config[:description] = description
    end

    def vendor(vendor)
      @config[:vendor] = vendor
    end

    def media_types(media_types)
      @config[:media_types] = media_types
    end

    def cors(options = {})
      allowed_options = default_cors_options.keys
      options = Utils.sanitize_keys(allowed_options, options)
      @config[:cors] = config[:cors].merge(options)
    end

    def per_page(per_page)
      per_page = per_page.to_i
      per_page = default_config[:per_page] if per_page == 0
      @config[:per_page] = per_page
    end

    def ssl(force_ssl)
      @config[:ssl] = force_ssl
    end

    def instrumenter(instrumenter)
      @config[:instrumenter] = instrumenter || Hyperdrive::Instrumenters::Noop
    end

    def resource(name, options = {})
      @resources[name] = Resource.new(name, options, &Proc.new).resource
    end

    def reset! # not terribly useful outside of a test environment :(
      @config = default_config.dup
      @resources = {}
    end
  end
end

def hyperdrive(&block)
  Hyperdrive::DSL.instance.instance_eval(&block) if block_given?
  Hyperdrive::DSL.instance
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 lib/hyperdrive/dsl.rb
hyperdrive-0.0.24 lib/hyperdrive/dsl.rb
hyperdrive-0.0.23 lib/hyperdrive/dsl.rb
hyperdrive-0.0.22 lib/hyperdrive/dsl.rb
hyperdrive-0.0.21 lib/hyperdrive/dsl.rb
hyperdrive-0.0.20 lib/hyperdrive/dsl.rb
hyperdrive-0.0.19 lib/hyperdrive/dsl.rb