Class: RequestType::Validator::ArrayWithDefault

Inherits:
Object
  • Object
show all
Defined in:
app/models/request_type/validator.rb

Overview

Array class that lets you set a default value If first argument is an array, second argument is assumed to be default Raises exception is default is not in the array In all other cases passes argument to standard array initializer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array, default) ⇒ ArrayWithDefault

Returns a new instance of ArrayWithDefault.

Raises:

  • (StandardError)


70
71
72
73
74
75
# File 'app/models/request_type/validator.rb', line 70

def initialize(array, default)
  raise StandardError, 'Default is not in array' unless array.include?(default)

  @default = default
  @array = array
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



77
78
79
# File 'app/models/request_type/validator.rb', line 77

def method_missing(method, ...)
  @array.send(method, ...)
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



68
69
70
# File 'app/models/request_type/validator.rb', line 68

def default
  @default
end

Instance Method Details

#to_aObject



83
84
85
# File 'app/models/request_type/validator.rb', line 83

def to_a
  @array
end