Class: CTioga2::Commands::CommandType
- Inherits:
-
Object
- Object
- CTioga2::Commands::CommandType
- Defined in:
- lib/ctioga2/commands/type.rb
Overview
Structural in real, I don’t think it is necessary
A named type, based on CTioga2::MetaBuilder::Type
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.
Instance Attribute Summary collapse
-
#context ⇒ Object
The context of definition [file, line].
-
#description ⇒ Object
The description of this type.
-
#name ⇒ Object
The unique identification of this type.
-
#type ⇒ Object
The underlying CTioga2::MetaBuilder::Type object.
Class Method Summary collapse
-
.get_type(obj) ⇒ Object
Makes sure the return value is a CommandType.
Instance Method Summary collapse
-
#boolean? ⇒ Boolean
Whether this is a boolean type or not.
-
#initialize(name, type, desc = nil) ⇒ CommandType
constructor
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.
-
#option_parser_long_option(name, param = nil) ⇒ Object
Returns the long option for the option parser.
-
#string_to_type(str) ⇒ Object
Does the actual conversion from string to the real type.
Constructor Details
#initialize(name, type, desc = nil) ⇒ CommandType
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 |
Instance Attribute Details
#context ⇒ Object
The context of definition [file, line]
39 40 41 |
# File 'lib/ctioga2/commands/type.rb', line 39 def context @context end |
#description ⇒ Object
The description of this type
36 37 38 |
# File 'lib/ctioga2/commands/type.rb', line 36 def description @description end |
#name ⇒ Object
The unique identification of this type.
33 34 35 |
# File 'lib/ctioga2/commands/type.rb', line 33 def name @name end |
#type ⇒ Object
The underlying CTioga2::MetaBuilder::Type object.
30 31 32 |
# File 'lib/ctioga2/commands/type.rb', line 30 def type @type end |
Class Method Details
.get_type(obj) ⇒ Object
Makes sure the return value is a CommandType. Will fail miserably if not.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 |
Instance Method Details
#boolean? ⇒ Boolean
Whether this is a boolean type or not.
84 85 86 |
# File 'lib/ctioga2/commands/type.rb', line 84 def boolean? return @type.boolean? end |
#option_parser_long_option(name, param = nil) ⇒ Object
Returns the long option for the option parser.
todo maybe this should be rethought a bit ?
96 97 98 |
# 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 |
#string_to_type(str) ⇒ Object
Does the actual conversion from string to the real type
89 90 91 |
# File 'lib/ctioga2/commands/type.rb', line 89 def string_to_type(str) return @type.string_to_type(str, @name) end |