Class: Tracksperanto::Parameters::Parameter

Inherits:
Object
  • Object
show all
Includes:
BlockInit
Defined in:
lib/tracksperanto/parameters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlockInit

#initialize

Instance Attribute Details

#castObject

The cast for the attribute (like :int or :float)


21
22
23
# File 'lib/tracksperanto/parameters.rb', line 21

def cast
  @cast
end

#defaultObject

Default value of the attribute


18
19
20
# File 'lib/tracksperanto/parameters.rb', line 18

def default
  @default
end

#descObject

Attribute description for the UI


24
25
26
# File 'lib/tracksperanto/parameters.rb', line 24

def desc
  @desc
end

#nameObject

The name of the paramenter and the related object attribute


12
13
14
# File 'lib/tracksperanto/parameters.rb', line 12

def name
  @name
end

#requiredObject

Whether the attribute is required


15
16
17
# File 'lib/tracksperanto/parameters.rb', line 15

def required
  @required
end

Instance Method Details

#apply_to(to_class) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tracksperanto/parameters.rb', line 26

def apply_to(to_class)
  to_class.send(:attr_accessor, name)
  
  if cast
    cast_call = "cast_to_#{cast}"
    to_class.send(cast_call, name)
  end
  
  if required
    to_class.safe_reader name
  end
  
end