class Af::OptionParser::OptionSelect
Constants
- FACTORY_SETTABLES
Attributes
var_name[RW]
Public Class Methods
new(var_name, parameters = {})
click to toggle source
Calls superclass method
Af::OptionParser::InstanceVariableSetter::new
# File lib/fiksu-af/option_parser/option_select.rb, line 12 def initialize(var_name, parameters = {}) super(parameters) @var_name = var_name end
Public Instance Methods
merge(that_option)
click to toggle source
Calls superclass method
Af::OptionParser::InstanceVariableSetter#merge
# File lib/fiksu-af/option_parser/option_select.rb, line 25 def merge(that_option) super(that_option, FACTORY_SETTABLES) end
set_instance_variables(parameters = {})
click to toggle source
+++++++++++++++++++++++
Calls superclass method
Af::OptionParser::InstanceVariableSetter#set_instance_variables
# File lib/fiksu-af/option_parser/option_select.rb, line 21 def set_instance_variables(parameters = {}) super(parameters, FACTORY_SETTABLES) end
validate()
click to toggle source
This methods validates the selected options based on the chosen action.
Available actions: one_of, none_or_one_of, one_or_more_of
If an invalidation occurs, an OptionSelectError
is raised with a specific message.
# File lib/fiksu-af/option_parser/option_select.rb, line 36 def validate # If an option_select is used, an array of options must be given if targets.blank? raise OptionSelectError.new("An array of options must be specified") end # Populate the options_set array with all instantiated class/instance variables options_set = [] targets.each do |target| if target_container.try(target.to_sym).present? options_set << target end end # Assign instantiated options to an instance variable if options_set.size == 1 value = options_set.first else value = options_set end target_container.instance_variable_set("@#{target_variable}", value) if action == :one_of && options_set.size != 1 raise OptionSelectError.new("You must specify only one of these options: --#{targets.join(', --')}") elsif action == :none_or_one_of && options_set.size > 1 raise OptionSelectError.new("You must specify no more than one of these options: --#{targets.join(', --')}") elsif action == :one_or_more_of && options_set.size < 1 raise OptionSelectError.new("You must specify at least one of these options: --#{targets.join(', --')}") end end