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.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ctioga2/commands/type.rb', line 68 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]
41 42 43 |
# File 'lib/ctioga2/commands/type.rb', line 41 def context @context end |
#description ⇒ Object
The description of this type
38 39 40 |
# File 'lib/ctioga2/commands/type.rb', line 38 def description @description end |
#name ⇒ Object
The unique identification of this type.
35 36 37 |
# File 'lib/ctioga2/commands/type.rb', line 35 def name @name end |
#type ⇒ Object
The underlying CTioga2::MetaBuilder::Type object.
32 33 34 |
# File 'lib/ctioga2/commands/type.rb', line 32 def type @type end |
Class Method Details
.get_type(obj) ⇒ Object
Makes sure the return value is a CommandType. Will fail miserably if not.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ctioga2/commands/type.rb', line 46 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.
86 87 88 |
# File 'lib/ctioga2/commands/type.rb', line 86 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 ?
98 99 100 |
# File 'lib/ctioga2/commands/type.rb', line 98 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
91 92 93 |
# File 'lib/ctioga2/commands/type.rb', line 91 def string_to_type(str) return @type.string_to_type(str) end |