Module: Rake::DSL

Defined in:
lib/hem/patches/rake.rb

Instance Method Summary collapse

Instance Method Details

#_old_namespaceObject



111
# File 'lib/hem/patches/rake.rb', line 111

alias :_old_namespace :namespace

#after(task_name, new_tasks = nil, &new_task) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hem/patches/rake.rb', line 22

def after(task_name, new_tasks = nil, &new_task)
  task_name = task_name.to_s
  new_tasks = [new_tasks].flatten.compact

  task = Rake::Task[task_name]
  task.enhance do
    new_tasks.each do |post_task|
      post = Rake.application.lookup(post_task, task.scope)
      raise ArgumentError, "Task #{post_task.inspect} not found" unless post
      post.invoke
    end
    new_task.call unless new_task.nil?
  end
end

#argument(name, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hem/patches/rake.rb', line 48

def argument name, options = {}
  opts = {
    optional: false,
    as: String,
  }.merge(options)
  Hem::Metadata.store[:arg_list] ||= {}

  if Hem::Metadata.store[:arg_list].length > 0
    last_arg = Hem::Metadata.store[:arg_list].values.last
    if last_arg[:optional] && !opts[:optional]
      raise 'Cannot have mandatory arguments after optional arguments'
    elsif last_arg[:as] == Array
      raise 'Cannot add any arguments after an array argument'
    end
  end

  Hem::Metadata.store[:arg_list][name] = opts
end

#before(task_name, new_tasks = nil, &new_task) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hem/patches/rake.rb', line 10

def before(task_name, new_tasks = nil, &new_task)
  task_name = task_name.to_s
  new_tasks = [new_tasks].flatten.compact
  old_task = Rake.application.instance_variable_get('@tasks').delete(task_name)

  Hem::Metadata.to_store task_name
  task task_name => old_task.prerequisites | new_tasks do
    new_task.call unless new_task.nil?
    old_task.invoke
  end
end

#desc(description) ⇒ Object



103
104
105
# File 'lib/hem/patches/rake.rb', line 103

def desc description
  Hem::Metadata.store[:desc] = description
end

#hidden(value = true) ⇒ Object



67
68
69
# File 'lib/hem/patches/rake.rb', line 67

def hidden value = true
  Hem::Metadata.store[:hidden] = value
end

#invoke(task, *args, &block) ⇒ Object



44
45
46
# File 'lib/hem/patches/rake.rb', line 44

def invoke task, *args, &block
  Rake::Task[task].invoke(*args, &block)
end

#long_desc(description) ⇒ Object



107
108
109
# File 'lib/hem/patches/rake.rb', line 107

def long_desc description
  Hem::Metadata.store[:long_desc] = description
end

#namespace(name, opts = {}, &block) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/hem/patches/rake.rb', line 112

def namespace name, opts = {}, &block
  scoped_name = Rake.application.current_scope.path_with_task_name(name).to_s
  [:desc, :long_desc, :hidden, :project_only].each do |meta|
    Hem::Metadata.add scoped_name, meta
  end

  Hem::Metadata.reset_store

  _old_namespace(name, &block)
end

#option(*args) ⇒ Object



99
100
101
# File 'lib/hem/patches/rake.rb', line 99

def option *args
  Hem::Metadata.store[:opts].push args
end

#plugins(setup = true, &block) ⇒ Object



123
124
125
126
127
# File 'lib/hem/patches/rake.rb', line 123

def plugins setup = true, &block
  Hem.plugins.define &block if block_given?
  Hem.plugins.setup if setup
  Hem.plugins
end

#project_onlyObject



71
72
73
# File 'lib/hem/patches/rake.rb', line 71

def project_only
  Hem::Metadata.store[:project_only] = true
end

#replace(*args, &block) ⇒ Object



37
38
39
40
41
42
# File 'lib/hem/patches/rake.rb', line 37

def replace *args, &block
  old = (args[0].is_a? Hash) ? args[0].keys[0] : args[0]
  Hem::Logging.logger.debug("rake.dsl: Replacing #{old} with block")
  Rake::Task[old].clear
  task(*args, &block)
end

#task(*args, &block) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/hem/patches/rake.rb', line 75

def task *args, &block
  name = args[0].is_a?(Hash) ? args[0].keys.first.to_s : args[0]
  scoped_name = Rake.application.current_scope.path_with_task_name(name).to_s
  Hem::Metadata.store[:arg_list] ||= {}

  args[1..-1].each do |name|
    argument name, optional: true
  end if args.length > 1

  [:opts, :desc, :long_desc, :hidden, :project_only, :arg_list].each do |meta|
    Hem::Metadata.add scoped_name, meta
  end

  if Hem::Metadata.store[:arg_list]
    args = [args[0], *Hem::Metadata.store[:arg_list].keys]
  end

  Hem::Metadata.reset_store

  Hem::Logging.logger.debug("Added metadata to #{scoped_name} -- #{Hem::Metadata.[scoped_name]}")

  task = Rake::Task.define_task(*args, &block)
end