Class: Quickl::Command::Builder
Instance Attribute Summary collapse
-
#doc_extractor ⇒ Object
Extractor for documentation.
-
#super_command ⇒ Object
The super command, if any.
Instance Method Summary collapse
-
#callback(&block) ⇒ Object
Installs a callback block to execute at install time.
-
#class_modules(*mods) ⇒ Object
(also: #class_module)
Adds some command class modules.
-
#document(file, line) ⇒ Object
Sets place of the documentation.
-
#instance_modules(*mods) ⇒ Object
(also: #instance_module)
Adds some command instance modules.
-
#run(command) ⇒ Object
Installs on a command subclass.
Instance Attribute Details
#doc_extractor ⇒ Object
Extractor for documentation
10 11 12 |
# File 'lib/quickl/command/builder.rb', line 10 def doc_extractor @doc_extractor end |
#super_command ⇒ Object
The super command, if any
6 7 8 |
# File 'lib/quickl/command/builder.rb', line 6 def super_command @super_command end |
Instance Method Details
#callback(&block) ⇒ Object
Installs a callback block to execute at install time
42 43 44 45 |
# File 'lib/quickl/command/builder.rb', line 42 def callback(&block) @callbacks ||= [] @callbacks << block end |
#class_modules(*mods) ⇒ Object Also known as: class_module
Adds some command class modules
21 22 23 24 25 26 27 |
# File 'lib/quickl/command/builder.rb', line 21 def class_modules(*mods) @class_modules ||= [ Command::ClassMethods, Command::Options::ClassMethods, ] @class_modules += mods end |
#document(file, line) ⇒ Object
Sets place of the documentation
13 14 15 16 17 18 |
# File 'lib/quickl/command/builder.rb', line 13 def document(file, line) @doc_extractor = lambda{|cmd, opts| text = RubyTools::extract_file_rdoc(file, line, true) cmd.instance_eval("%Q{#{text}}", file, line) } end |
#instance_modules(*mods) ⇒ Object Also known as: instance_module
Adds some command instance modules
31 32 33 34 35 36 37 |
# File 'lib/quickl/command/builder.rb', line 31 def instance_modules(*mods) @instance_modules ||= [ Command::InstanceMethods, Command::Options::InstanceMethods ] @instance_modules += mods end |
#run(command) ⇒ Object
Installs on a command subclass
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/quickl/command/builder.rb', line 48 def run(command) # install class and instance methods class_modules.each{|mod| command.extend(mod) } instance_modules.each{|mod| command.instance_eval{ include mod } } # install documentation self.doc_extractor ||= lambda{|cmd, opts| "no documentation available for #{cmd}" } command.doc_extractor = doc_extractor # install hierarchy self.super_command ||= RubyTools::parent_module(command) if super_command && super_command.ancestors.include?(Command) command.super_command = super_command super_command.subcommands << command end # execute callbacks Array(@callbacks).each do |blk| blk.call(command) end if defined?(@callbacks) command end |