Class: Ablerc::Option

Inherits:
Hashie::Dash
  • Object
show all
Defined in:
lib/ablerc/option.rb

Overview

An option is a declared attribute within an rc file, in other words, an uncommented key-value pair.

Options define how an attribute behaves (via behavior parameters), which are used to validate, explain and control default values for the option.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, behaviors = {}, &block) ⇒ Option

Initialize the option

Parameters

  • name - A valid name for the option

  • behaviors - Behaviors used to for this option

  • block - A proc that should be run against the option value.

Options

  • allow - The option value must be in this list

  • boolean - The option will accept true, false, 0, 1



26
27
28
29
# File 'lib/ablerc/option.rb', line 26

def initialize(name, behaviors = {}, &block)
    self.name = name
    extract_behaviors( behaviors )
end

Instance Attribute Details

#allowsObject

Returns the value of attribute allows.



15
16
17
# File 'lib/ablerc/option.rb', line 15

def allows
  @allows
end

#booleanObject

Returns the value of attribute boolean.



15
16
17
# File 'lib/ablerc/option.rb', line 15

def boolean
  @boolean
end

#defaultObject

Returns the value of attribute default.



15
16
17
# File 'lib/ablerc/option.rb', line 15

def default
  @default
end

#descriptionObject

Returns the value of attribute description.



15
16
17
# File 'lib/ablerc/option.rb', line 15

def description
  @description
end

#disabledObject

Returns the value of attribute disabled.



15
16
17
# File 'lib/ablerc/option.rb', line 15

def disabled
  @disabled
end

#refusesObject

Returns the value of attribute refuses.



15
16
17
# File 'lib/ablerc/option.rb', line 15

def refuses
  @refuses
end

Instance Method Details

#to_stubObject



32
33
34
35
36
37
38
# File 'lib/ablerc/option.rb', line 32

def to_stub
  stub = "## #{name}\n"
  stub << "# #{description}\n" unless description.nil?
  stub << "#{entry_for_refuse_allow_behavior}\n" unless refuses.nil? and allows.nil?
  stub << "#{entry_for_key_value}\n"
  stub << "\n"
end