Class: Shaf::Authenticator::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/shaf/authenticator/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, required: true, default: nil, values: nil) ⇒ Parameter

Returns a new instance of Parameter.



8
9
10
11
12
13
# File 'lib/shaf/authenticator/parameter.rb', line 8

def initialize(name, required: true, default: nil, values: nil)
  @name = name
  @required = required
  @default = default
  @values = values&.map(&:downcase)
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/shaf/authenticator/parameter.rb', line 6

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/shaf/authenticator/parameter.rb', line 6

def name
  @name
end

#valuesObject (readonly)

Returns the value of attribute values.



6
7
8
# File 'lib/shaf/authenticator/parameter.rb', line 6

def values
  @values
end

Instance Method Details

#optional?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/shaf/authenticator/parameter.rb', line 19

def optional?
  !required?
end

#required?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/shaf/authenticator/parameter.rb', line 15

def required?
  @required
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/shaf/authenticator/parameter.rb', line 23

def valid?(value)
  return optional? if value.nil?
  return true unless values

  values.include?(value.downcase)
end