Module: Tap::Declarations

Included in:
Tap
Defined in:
lib/tap/declarations.rb

Defined Under Namespace

Modules: Lazydoc, Rakish

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_descObject

Returns the value of attribute current_desc.


54
55
56
# File 'lib/tap/declarations.rb', line 54

def current_desc
  @current_desc
end

#declaration_baseObject

Returns the value of attribute declaration_base.


52
53
54
# File 'lib/tap/declarations.rb', line 52

def declaration_base
  @declaration_base
end

Class Method Details

.envObject


44
45
46
# File 'lib/tap/declarations.rb', line 44

def self.env
  @env ||= Tap::Env.new(:load_paths => [], :command_paths => [], :generator_paths => [])
end

.extended(base) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'lib/tap/declarations.rb', line 33

def self.extended(base)
  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

#desc(str) ⇒ Object


95
96
97
98
# File 'lib/tap/declarations.rb', line 95

def desc(str)
  self.current_desc = Lazydoc::Comment.new
  current_desc.subject = str
end

#envObject


48
49
50
# File 'lib/tap/declarations.rb', line 48

def env
  @env ||= Declarations.env
end

#namespace(name, &block) ⇒ Object


88
89
90
91
92
93
# File 'lib/tap/declarations.rb', line 88

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


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/tap/declarations.rb', line 56

def task(*args, &block)
  const_name, configs, dependencies, arg_names = resolve_args(args)
  task_class = declare(const_name, configs, dependencies) do |*inputs|
    # collect inputs to make a rakish-args object
    args = {}
    arg_names.each do |arg_name|
      break if inputs.empty?
      args[arg_name] = inputs.shift
    end
    args = OpenStruct.new(args)
    
    # execute each block assciated with this task
    self.class::BLOCKS.each do |task_block|
      case task_block.arity
      when 0 then task_block.call()
      when 1 then task_block.call(self)
      else task_block.call(self, args)
      end
    end
    
    nil
  end
  register_doc(task_class, arg_names)
  
  # add the block to the task
  unless task_class.const_defined?(:BLOCKS)
    task_class.const_set(:BLOCKS, [])
  end
  task_class::BLOCKS << block unless block == nil
  task_class.instance
end