Module: RequestParamsValidation::Definitions

Defined in:
lib/request_params_validation/definitions.rb,
lib/request_params_validation/definitions/param.rb,
lib/request_params_validation/definitions/action.rb,
lib/request_params_validation/definitions/request.rb,
lib/request_params_validation/definitions/resource.rb

Defined Under Namespace

Classes: Action, Param, Request, Resource

Constant Summary collapse

@@definitions =
{}

Class Method Summary collapse

Class Method Details

.get_request(resource, action) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/request_params_validation/definitions.rb', line 24

def self.get_request(resource, action)
  resource = @@definitions[resource]

  return unless resource

  action = resource.actions[action]

  return unless action

  action.request
end

.load_all(use_load = false) ⇒ Object



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

def self.load_all(use_load = false)
  definitions_suffix = RequestParamsValidation.definitions_suffix
  Dir["#{definitions_path}/**/*#{definitions_suffix}.rb"].each { |f| use_load ? load(f) : require(f) }
end

.register_resource(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/request_params_validation/definitions.rb', line 13

def self.register_resource(&block)
  raise DefinitionArgumentError.new('Expecting block for resource definition') unless block_given?

  resource_name = resource_name_from_block(&block)
  resource = Resource.new(resource_name)

  resource.instance_eval(&block)

  @@definitions[resource_name] = resource
end