Class: ViewSpec::Param

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
lib/view_spec/param.rb

Constant Summary collapse

NO_DEFAULT =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cast_type = nil, value: nil, default: NO_DEFAULT, **type_options) ⇒ Param

Returns a new instance of Param.



10
11
12
13
14
15
16
# File 'lib/view_spec/param.rb', line 10

def initialize(name, cast_type = nil, value: nil, default: NO_DEFAULT, **type_options)
  @name = name.to_sym
  @cast_type = cast_type
  @value = value
  @default = default
  @type_options = type_options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/view_spec/param.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/view_spec/param.rb', line 8

def options
  @options
end

Instance Method Details

#defaultObject



26
27
28
# File 'lib/view_spec/param.rb', line 26

def default
  (@default == NO_DEFAULT) ? nil : @default
end

#default?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/view_spec/param.rb', line 30

def default?
  @default != NO_DEFAULT
end

#to_pairObject



34
35
36
# File 'lib/view_spec/param.rb', line 34

def to_pair
  [name, value]
end

#typeObject



22
23
24
# File 'lib/view_spec/param.rb', line 22

def type
  @type ||= Type.for(@cast_type, **@type_options)
end

#valueObject



18
19
20
# File 'lib/view_spec/param.rb', line 18

def value
  type.cast(raw_value)
end