Module Tap::Declarations
In: lib/tap/declarations.rb
lib/tap/declarations/context.rb
lib/tap/declarations/description.rb

Methods

baseclass   declare   desc   env   initialize_declare   join   namespace   node   singleton   task   work  

Classes and Modules

Class Tap::Declarations::Context
Class Tap::Declarations::Description

Public Instance methods

[Source]

    # File lib/tap/declarations.rb, line 44
44:     def baseclass(baseclass=Tap::Task)
45:       current = @baseclass
46:       begin
47:         @baseclass = env.constant(baseclass) unless baseclass.nil?
48:         yield if block_given?
49:       ensure
50:         @baseclass = current if block_given?
51:       end
52:     end

[Source]

     # File lib/tap/declarations.rb, line 74
 74:     def declare(baseclass, const_name, configs={}, &block)
 75:       const_name = const_name.to_s.camelize
 76:       subclass = Class.new(env.constant(baseclass))
 77:       @namespace.const_set(const_name, subclass)
 78:       
 79:       # define configs
 80:       configs.each_pair do |key, value|
 81:         # specifying a desc prevents lazydoc registration of these lines
 82:         opts = {:desc => ""}
 83:         opts[:short] = key if key.to_s.length == 1
 84:         config_block = Configurable::Validation.guess(value)
 85:         subclass.send(:config, key, value, opts, &config_block)
 86:       end
 87:       
 88:       # define process
 89:       if block
 90:         # determine arity, correcting for the self arg
 91:         arity = block.arity
 92:         arity -= arity > 0 ? 1 : -1
 93:         signature = Array.new(arity < 0 ? arity.abs - 1 : arity, 'arg')
 94:         signature << '*args' if arity < 0
 95:         
 96:         # prevents assessment of process args by lazydoc
 97:         subclass.const_attrs[:process] = signature.join(' ')
 98:         subclass.send(:define_method, :process) do |*args|
 99:           block.call(self, *args)
100:         end
101:       end
102:       
103:       # register documentation
104:       constant = env.set(subclass, nil)
105:       
106:       if @desc
107:         subclass.desc = @desc
108:         constant.register_as(subclass.type, @desc)
109:         @desc = nil
110:       end
111:       
112:       subclass
113:     end

Sets the description for use by the next task declaration.

[Source]

    # File lib/tap/declarations.rb, line 34
34:     def desc(str)
35:       @desc = Lazydoc.register_caller(Description)
36:       @desc.desc = str
37:       @desc
38:     end

[Source]

    # File lib/tap/declarations.rb, line 10
10:     def env
11:       app.env
12:     end

Generates a join between the inputs and outputs. Join resolves the class using env and initializes a new instance with the configs and self.

[Source]

    # File lib/tap/declarations.rb, line 24
24:     def  joinjoin(inputs, outputs, config={}, clas=Tap::Join, &block)
25:       inputs  = [inputs]  unless inputs.kind_of?(Array)
26:       outputs = [outputs] unless outputs.kind_of?(Array)
27:       
28:       obj = app.init(clas, config, app)
29:       obj.join(inputs, outputs, &block)
30:       obj
31:     end

Nests tasks within the named module for the duration of the block. Namespaces may be nested.

[Source]

    # File lib/tap/declarations.rb, line 56
56:     def namespace(namespace)
57:       current = @namespace
58:       begin
59:         unless namespace.nil? || namespace.kind_of?(Module)
60:           const_name = namespace.to_s.camelize
61:           unless current.const_defined?(const_name)
62:             current.const_set(const_name, Module.new)
63:           end
64:           namespace = current.const_get(const_name)
65:         end
66:         
67:         @namespace = namespace unless namespace.nil?
68:         yield if block_given?
69:       ensure
70:         @namespace = current if block_given?
71:       end
72:     end

Returns a new node that executes block on call.

[Source]

    # File lib/tap/declarations.rb, line 15
15:     def node(var=nil, &node) # :yields: *args
16:       def node.joins; @joins ||= []; end
17:       app.set(var, node) if var
18:       node
19:     end

[Source]

    # File lib/tap/declarations.rb, line 40
40:     def singleton(&block)
41:       baseclass(Tap::Tasks::Singleton, &block)
42:     end

[Source]

     # File lib/tap/declarations.rb, line 115
115:     def task(const_name, configs={}, baseclass=@baseclass, &block)
116:       @desc ||= Lazydoc.register_caller(Description)
117:       const_name, prerequisites = parse_prerequisites(const_name)
118: 
119:       if prerequisites.nil?
120:         return declare(baseclass, const_name, configs, &block)
121:       end
122: 
123:       tasc = declare(Tap::Workflow, const_name, configs) do |workflow|
124:         psr = Parser.new
125:         args = psr.parse!(prerequisites)
126:         warn "ignoring args: #{args.inspect}" unless args.empty?
127:         psr.build_to(app)
128:         
129:         obj = init("#{const_name.to_s.underscore}/task", workflow.config.to_hash)
130:         setup = lambda {|input| exe(obj, input) }
131:         
132:         [setup, obj]
133:       end
134: 
135:       namespace(const_name) do
136:         declare(baseclass, 'Task', configs, &block)
137:       end
138: 
139:       tasc
140:     end

[Source]

     # File lib/tap/declarations.rb, line 142
142:     def work(const_name, definition, configs={}, baseclass=Tap::Workflow, &block)
143:       unless definition.kind_of?(String)
144:         raise "workflow definition must be a string: #{definition.inspect}"
145:       end
146:       
147:       @desc ||= Lazydoc.register_caller(Description)
148:       block ||= lambda {|config| node(0) }
149:       task({const_name => definition}, configs, baseclass, &block)
150:     end

Protected Instance methods

[Source]

     # File lib/tap/declarations.rb, line 154
154:     def initialize_declare(baseclass=Tap::Task, namespace=Object)
155:       @desc = nil
156:       @baseclass = baseclass
157:       @namespace = namespace
158:     end

[Validate]