Attribute::Definition
# File lib/clamp/option/definition.rb, line 9 def initialize(switches, type, description, options = {}) @switches = Array(switches) @type = type @description = description super(options) @multivalued = options[:multivalued] if options.has_key?(:required) @required = options[:required] # Do some light validation for conflicting settings. if options.has_key?(:default) raise ArgumentError, "Specifying a :default value also :required doesn't make sense" end if type == :flag raise ArgumentError, "A required flag (boolean) doesn't make sense." end end end
# File lib/clamp/option/definition.rb, line 61 def default_conversion_block if flag? Clamp.method(:truthy?) end end
# File lib/clamp/option/definition.rb, line 53 def extract_value(switch, arguments) if flag? flag_value(switch) else arguments.shift end end
# File lib/clamp/option/definition.rb, line 37 def flag? @type == :flag end
# File lib/clamp/option/definition.rb, line 41 def flag_value(switch) !(switch =~ /^--no-(.*)/ && switches.member?("--\[no-\]#{$1}")) end
# File lib/clamp/option/definition.rb, line 33 def handles?(switch) recognised_switches.member?(switch) end
# File lib/clamp/option/definition.rb, line 67 def help_lhs lhs = switches.join(", ") lhs += " " + type unless flag? lhs end
Generated with the Darkfish Rdoc Generator 2.