Class: Undestroy::Config::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/undestroy/config/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, value = nil, &block) ⇒ Field

Returns a new instance of Field.



9
10
11
12
13
# File 'lib/undestroy/config/field.rb', line 9

def initialize(name, type, value=nil, &block)
  self.name = name
  self.type = type
  self.raw_value = block || value || raise(ArgumentError, "Must pass a value or block")
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/undestroy/config/field.rb', line 3

def name
  @name
end

#raw_valueObject

Returns the value of attribute raw_value.



3
4
5
# File 'lib/undestroy/config/field.rb', line 3

def raw_value
  @raw_value
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/undestroy/config/field.rb', line 3

def type
  @type
end

Instance Method Details

#<=>(b) ⇒ Object



5
6
7
# File 'lib/undestroy/config/field.rb', line 5

def <=>(b)
  name.to_s <=> b.name.to_s
end

#value(*args) ⇒ Object



15
16
17
# File 'lib/undestroy/config/field.rb', line 15

def value(*args)
  raw_value.is_a?(Proc) ? raw_value.call(*args) : raw_value
end