Class: Sekisyo::WhitelistDetails::Properties

Inherits:
Object
  • Object
show all
Defined in:
lib/sekisyo/whitelist_details/properties.rb

Overview

Sekisyo WhitelistDetails Path is a definition object for each properties in the whitelist.

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ Properties

Returns a new instance of Properties.



11
12
13
14
15
16
# File 'lib/sekisyo/whitelist_details/properties.rb', line 11

def initialize(properties = {})
  @permit_keys = properties.keys
  @properties = properties.map do |k, v|
    Sekisyo::Validator.new(k, v || {})
  end
end

Instance Method Details

#valid?(params) ⇒ true, false

Parameters:

  • params (Hash)

    Request parameter.

Returns:

  • (true, false)


23
24
25
26
27
28
29
30
# File 'lib/sekisyo/whitelist_details/properties.rb', line 23

def valid?(params)
  return false unless params.is_a? Hash
  return false unless params == params.slice(*@permit_keys)

  params.all? do |k, v|
    @properties.find { |validator| validator.key == k }&.valid?(v)
  end
end