Sha256: d850cb4f6f5bf0710e40c32eb6ee8b1b3674b1ea60f2a6aa885280ada48803c0

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

module Hyperdrive
  module DSL
    class Resource
      include Values
      attr_reader :resource
      def initialize(name, hyperdrive_config)
        @resource = ::Hyperdrive::Resource.new(name, hyperdrive_config)
        instance_eval(&Proc.new) if block_given?
      end

      def name(name)
        resource.name = name
      end

      def description(description)
        resource.description = description
      end

      def param(*args)
        resource.register_param(*args)
      end

      def filter(*args)
        resource.register_filter(*args)
      end

      def request(request_method, version = 'v1')
        unless definable_request_methods.include? request_method
          raise Errors::DSL::UnknownArgument.new(request_method, 'request')
        end
        resource.register_request_handler(request_method, Proc.new, version)
      end

      def before(request_methods = [:get, :post, :put, :patch, :delete], version = 'v1')
        Array(request_methods).each do |request_method|
          resource.register_callback(:before, request_method, Proc.new, version)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hyperdrive-0.0.18 lib/hyperdrive/dsl/resource.rb
hyperdrive-0.0.17 lib/hyperdrive/dsl/resource.rb
hyperdrive-0.0.16 lib/hyperdrive/dsl/resource.rb