Module: MetaBuilder::DescriptionInclude
- Included in:
- CTioga::PlotMaker, SciYAG::Backends::Backend
- Defined in:
- lib/MetaBuilder/descriptions.rb
Overview
This module should be used in conjunction with DescriptionExtend to provide Descriptions to a class or a family of classes:
class NiceClass
extend DescriptionExtend
include DescriptionInclude
# real code now
end
The DescriptionInclude in itself provide some small facilities: a mehod to access directly the #description of an object (and its #long_name), a series of methods to set|get parameters based on their name (#parameter, #get_param, #get_param_raw, #set_param, #set_param_raw) and some methods to fill an OptionParser (#option_parser_fill, #option_parser_options, #option_parser_banner)
Instance Method Summary collapse
-
#description ⇒ Object
Returns the description associated with the class.
-
#get_param(p) ⇒ Object
Query the value of a parameter, returns a String.
-
#get_param_raw(p) ⇒ Object
Query the value of a parameter, returns the actual value.
-
#long_name ⇒ Object
Returns the long name of the class.
-
#option_parser_banner(parser) ⇒ Object
Provides only a banner for the current class to the OptionParser parser.
-
#option_parser_fill(parser, uniquify = true, groups = false) ⇒ Object
Fills an OptionParser with their parameters.
-
#option_parser_options(parser, uniquify = true, groups = false) ⇒ Object
Prepares an option parser for this instance.
-
#parameter(param) ⇒ Object
Returns the Parameter object associated with the named parameter.
-
#restore_state(state) ⇒ Object
Restores a previously saved state.
-
#save_state ⇒ Object
Calls Description#save_state on this object.
-
#set_param(param, str) ⇒ Object
Sets the value of a paramete according to a String.
-
#set_param_raw(param, val) ⇒ Object
Sets directly the value of a parameter.
Instance Method Details
#description ⇒ Object
Returns the description associated with the class.
301 302 303 |
# File 'lib/MetaBuilder/descriptions.rb', line 301 def description return self.class.description end |
#get_param(p) ⇒ Object
Query the value of a parameter, returns a String
321 322 323 |
# File 'lib/MetaBuilder/descriptions.rb', line 321 def get_param(p) return parameter(p).get(self) end |
#get_param_raw(p) ⇒ Object
Query the value of a parameter, returns the actual value
326 327 328 |
# File 'lib/MetaBuilder/descriptions.rb', line 326 def get_param_raw(p) return parameter(p).get_raw(self) end |
#long_name ⇒ Object
Returns the long name of the class
307 308 309 |
# File 'lib/MetaBuilder/descriptions.rb', line 307 def long_name return description.long_name end |
#option_parser_banner(parser) ⇒ Object
Provides only a banner for the current class to the OptionParser parser.
354 355 356 |
# File 'lib/MetaBuilder/descriptions.rb', line 354 def (parser) description.(parser, self) end |
#option_parser_fill(parser, uniquify = true, groups = false) ⇒ Object
Fills an OptionParser with their parameters. Most probably, the default implementation should do for most cases. uniquify asks if we should try to make the command-line options as unique as reasonable to do. If groups is true, organize parameters in groups.
347 348 349 350 |
# File 'lib/MetaBuilder/descriptions.rb', line 347 def option_parser_fill(parser, uniquify = true, groups = false) description.option_parser_fill(parser, self, uniquify, groups) end |
#option_parser_options(parser, uniquify = true, groups = false) ⇒ Object
Prepares an option parser for this instance. See Description#option_parser_options
360 361 362 |
# File 'lib/MetaBuilder/descriptions.rb', line 360 def (parser, uniquify = true, groups = false) description.(parser, self, uniquify, groups) end |
#parameter(param) ⇒ Object
Returns the Parameter object associated with the named parameter
316 317 318 |
# File 'lib/MetaBuilder/descriptions.rb', line 316 def parameter(param) return description.param_hash.fetch(param) end |
#restore_state(state) ⇒ Object
Restores a previously saved state. (Well, it doesn’t need to be previously saved, you can make it up if you like).
373 374 375 |
# File 'lib/MetaBuilder/descriptions.rb', line 373 def restore_state(state) description.restore_state(state, self) end |
#save_state ⇒ Object
Calls Description#save_state on this object
367 368 369 |
# File 'lib/MetaBuilder/descriptions.rb', line 367 def save_state return description.save_state(self) end |
#set_param(param, str) ⇒ Object
Sets the value of a paramete according to a String
331 332 333 |
# File 'lib/MetaBuilder/descriptions.rb', line 331 def set_param(param, str) return parameter(param).set(self, str) end |
#set_param_raw(param, val) ⇒ Object
Sets directly the value of a parameter
336 337 338 |
# File 'lib/MetaBuilder/descriptions.rb', line 336 def set_param_raw(param, val) return parameter(param).set_raw(self, val) end |