Class: ENVied::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/envied/variable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, **options) ⇒ Variable

Returns a new instance of Variable.



4
5
6
7
8
9
10
11
12
13
# File 'lib/envied/variable.rb', line 4

def initialize(name, type, **options)
  @name = name.to_sym
  @type = type.to_sym
  @group = options.fetch(:group, :default).to_sym
  @default = options[:default]

  #if [email protected]_a? String
  #  raise ArgumentError, "Default values should be strings (variable #{@name})"
  #end
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



2
3
4
# File 'lib/envied/variable.rb', line 2

def default
  @default
end

#groupObject (readonly)

Returns the value of attribute group.



2
3
4
# File 'lib/envied/variable.rb', line 2

def group
  @group
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/envied/variable.rb', line 2

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/envied/variable.rb', line 2

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
# File 'lib/envied/variable.rb', line 19

def ==(other)
  self.class == other.class &&
    [name, type, group, default] == [other.name, other.type, other.group, other.default]
end

#default_value(*args) ⇒ Object



15
16
17
# File 'lib/envied/variable.rb', line 15

def default_value(*args)
  default.respond_to?(:call) ? default[*args] : default
end