Class: RequestParamsValidation::Definitions::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/request_params_validation/definitions/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Resource

Returns a new instance of Resource.



9
10
11
12
# File 'lib/request_params_validation/definitions/resource.rb', line 9

def initialize(name)
  @name = name
  @actions = {}
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



7
8
9
# File 'lib/request_params_validation/definitions/resource.rb', line 7

def actions
  @actions
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/request_params_validation/definitions/resource.rb', line 7

def name
  @name
end

Instance Method Details

#action(action_name, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/request_params_validation/definitions/resource.rb', line 14

def action(action_name, &block)
  unless block_given?
    raise DefinitionArgumentError.new("Expecting block for action '#{action_name}'")
  end

  action = Action.new(action_name.to_s)

  action.instance_eval(&block)

  @actions[action_name.to_s] = action
rescue DefinitionArgumentError => e
  e.resource = name
  raise
end