class CTioga2::Commands::CommandType
A named type, based on CTioga2::MetaBuilder::Type
@todo Structural in real, I don't think it is necessary anymore to rely on MetaBuilder
, as most types in CTioga2
already provide a from_text class function that does a nice job. I should convert as many things as possible to using that.
Attributes
The context of definition [file, line]
The description of this type
The unique identification of this type.
The underlying CTioga2::MetaBuilder::Type
object.
Public Class Methods
Makes sure the return value is a CommandType
. Will fail miserably if not.
# File lib/ctioga2/commands/type.rb, line 44 def self.get_type(obj) if obj.is_a? CommandType return obj else if obj.is_a? Symbol warn { "Converting type specification #{obj.inspect} to string at #{caller[1]}" } obj = obj.to_s end type = Interpreter::type(obj) if type return type else raise InvalidType, "Type #{obj.inspect} unknown" end end end
type is the type of the argument in a descriptive fashion, as could be fed to CTioga2::MetaBuilder::Type.get_type
, or directly a MetaBuilder::Type
object.
# File lib/ctioga2/commands/type.rb, line 66 def initialize(name, type, desc = nil) if type.is_a? MetaBuilder::Type @type = type else @type = CTioga2::MetaBuilder::Type.get_type(type) end @name = name @description = desc caller[1].gsub(/.*\/ctioga2\//, 'lib/ctioga2/') =~ /(.*):(\d+)/ @context = [$1, $2.to_i] Interpreter::register_type(self) end
Public Instance Methods
Whether this is a boolean type or not.
# File lib/ctioga2/commands/type.rb, line 84 def boolean? return @type.boolean? end
Returns the long option for the option parser.
todo maybe this should be rethought a bit ?
# File lib/ctioga2/commands/type.rb, line 96 def option_parser_long_option(name, param = nil) return @type.option_parser_long_option(name, param) end
Does the actual conversion from string to the real type
# File lib/ctioga2/commands/type.rb, line 89 def string_to_type(str) return @type.string_to_type(str, @name) end