Class: Foreman::Parameters::Caster

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman/parameters/caster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, options = {}) ⇒ Caster

Returns a new instance of Caster.


6
7
8
9
10
11
12
13
14
# File 'app/services/foreman/parameters/caster.rb', line 6

def initialize(item, options = {})
  defaults = {
    :attribute_name => :value,
    :to => :string,
  }
  options.reverse_merge!(defaults)
  @item, @options = item, options
  @value = @options[:value].nil? ? @item.send(@options[:attribute_name]) : @options[:value]
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value


4
5
6
# File 'app/services/foreman/parameters/caster.rb', line 4

def value
  @value
end

Instance Method Details

#castObject


20
21
22
# File 'app/services/foreman/parameters/caster.rb', line 20

def cast
  casted_value
end

#cast!Object


16
17
18
# File 'app/services/foreman/parameters/caster.rb', line 16

def cast!
  @item.send("#{@options[:attribute_name]}=", casted_value)
end