Module: Tap::Declarations
- Includes:
- Support::ShellUtils
- Included in:
- Tap
- Defined in:
- lib/tap/declarations.rb,
lib/tap/declarations/description.rb,
lib/tap/declarations/declaration_task.rb
Overview
– more thought needs to go into extending Tap with Declarations and there should be some discussion on why include works at the top level (for main/Object) while extend should be used in all other cases.
Defined Under Namespace
Classes: DeclarationTask, Description
Instance Attribute Summary collapse
-
#current_desc ⇒ Object
Tracks the current description, which will be used to document the next task declaration.
-
#declaration_base ⇒ Object
The base constant for all task declarations, prepended to the task name.
Class Method Summary collapse
-
.env ⇒ Object
The Tap::Env for Dir.pwd.
-
.extended(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#declaration_env ⇒ Object
The environment in which declared task classes are registered.
-
#desc(str) ⇒ Object
Sets the current description for use by the next task declaration.
-
#namespace(name, &block) ⇒ Object
Appends name to the declaration base for the duration of the block.
-
#task(*args, &block) ⇒ Object
Declares a task with a rake-like syntax.
Methods included from Support::ShellUtils
#capture_sh, #redirect_sh, #sh
Instance Attribute Details
#current_desc ⇒ Object
Tracks the current description, which will be used to document the next task declaration.
47 48 49 |
# File 'lib/tap/declarations.rb', line 47 def current_desc @current_desc ||= nil end |
#declaration_base ⇒ Object
The base constant for all task declarations, prepended to the task name.
39 40 41 |
# File 'lib/tap/declarations.rb', line 39 def declaration_base @declaration_base ||= '' end |
Class Method Details
.env ⇒ Object
The Tap::Env for Dir.pwd
26 27 28 |
# File 'lib/tap/declarations.rb', line 26 def self.env @env ||= Tap::Env.instance_for(Dir.pwd) end |
.extended(base) ⇒ Object
:nodoc:
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tap/declarations.rb', line 14 def self.extended(base) # :nodoc: declaration_base = base.to_s case declaration_base when "Object", "Tap", "main" declaration_base = "" end base.instance_variable_set(:@declaration_base, declaration_base.underscore) base.instance_variable_set(:@current_desc, nil) end |
Instance Method Details
#declaration_env ⇒ Object
The environment in which declared task classes are registered. By default Declarations.env
32 33 34 |
# File 'lib/tap/declarations.rb', line 32 def declaration_env @declaration_env ||= Declarations.env end |
#desc(str) ⇒ Object
Sets the current description for use by the next task declaration.
78 79 80 |
# File 'lib/tap/declarations.rb', line 78 def desc(str) self.current_desc = str end |
#namespace(name, &block) ⇒ Object
Appends name to the declaration base for the duration of the block. This has the effect of nesting any task declarations within the Name module or class.
70 71 72 73 74 75 |
# File 'lib/tap/declarations.rb', line 70 def namespace(name, &block) current_base = declaration_base @declaration_base = File.join(current_base, name.to_s.underscore) yield @declaration_base = current_base end |
#task(*args, &block) ⇒ Object
Declares a task with a rake-like syntax
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tap/declarations.rb', line 52 def task(*args, &block) task_name, configs, needs, arg_names = resolve_args(args) task_class = declare(task_name, configs, needs) # set the arg_names for the subclass task_class.arg_names = arg_names # register the current_desc register_doc(task_class) # add the block to the task task_class.blocks << block if block task_class.instance end |