Class: ParamGuard::ParamDefinition

Inherits:
Struct
  • Object
show all
Defined in:
lib/param_guard/param_definition.rb

Overview

Rules describing the requirements for a parameter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#presenceObject

Returns the value of attribute presence

Returns:

  • (Object)

    the current value of presence



4
5
6
# File 'lib/param_guard/param_definition.rb', line 4

def presence
  @presence
end

#subdefObject

Returns the value of attribute subdef

Returns:

  • (Object)

    the current value of subdef



4
5
6
# File 'lib/param_guard/param_definition.rb', line 4

def subdef
  @subdef
end

#type_or_typesObject

Returns the value of attribute type_or_types

Returns:

  • (Object)

    the current value of type_or_types



4
5
6
# File 'lib/param_guard/param_definition.rb', line 4

def type_or_types
  @type_or_types
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/param_guard/param_definition.rb', line 5

def required?
  presence == :required
end

#typesObject



9
10
11
# File 'lib/param_guard/param_definition.rb', line 9

def types
  Array(type_or_types)
end

#types_for_sentenceObject



13
14
15
16
17
# File 'lib/param_guard/param_definition.rb', line 13

def types_for_sentence
  a = types.map(&:to_s)
  return nil if a.empty?
  [a[0..-3] + [a.last(2).join(' or ')]].compact.join(', ')
end