Class: ViewSpec::Param

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Param.



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

def initialize(name, cast_type = nil, value: nil, default: nil, **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.



6
7
8
# File 'lib/view_spec/param.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/view_spec/param.rb', line 6

def options
  @options
end

Instance Method Details

#to_pairObject



24
25
26
# File 'lib/view_spec/param.rb', line 24

def to_pair
  [name, value]
end

#typeObject



20
21
22
# File 'lib/view_spec/param.rb', line 20

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

#valueObject



16
17
18
# File 'lib/view_spec/param.rb', line 16

def value
  type.cast(raw_value)
end