Class: Hyperdrive::DSL::Resource

Inherits:
Object
  • Object
show all
Includes:
Values
Defined in:
lib/hyperdrive/dsl/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Values

default_config, default_cors_options, default_headers, definable_request_methods, http_request_methods, request_methods, supported_request_methods

Constructor Details

#initialize(name, options = {}) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
# File 'lib/hyperdrive/dsl/resource.rb', line 8

def initialize(name, options = {})
  @resource = ::Hyperdrive::Resource.new(name, options)
  instance_eval(&Proc.new) if block_given?
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/hyperdrive/dsl/resource.rb', line 7

def resource
  @resource
end

Instance Method Details

#before(request_methods = [:get, :post, :put, :patch, :delete], version = 'v1') ⇒ Object



36
37
38
39
40
# File 'lib/hyperdrive/dsl/resource.rb', line 36

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

#description(description) ⇒ Object



17
18
19
# File 'lib/hyperdrive/dsl/resource.rb', line 17

def description(description)
  resource.description = description
end

#filter(*args) ⇒ Object



25
26
27
# File 'lib/hyperdrive/dsl/resource.rb', line 25

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

#name(name) ⇒ Object



13
14
15
# File 'lib/hyperdrive/dsl/resource.rb', line 13

def name(name)
  resource.name = name
end

#param(*args) ⇒ Object



21
22
23
# File 'lib/hyperdrive/dsl/resource.rb', line 21

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

#request(request_method, version = 'v1') ⇒ Object



29
30
31
32
33
34
# File 'lib/hyperdrive/dsl/resource.rb', line 29

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