Module: Pult::Panel::Provider::Rake

Defined in:
lib/init/struct.rb,
lib/pult/panel/provider/rake.rb

Constant Summary collapse

FILE =
'Rakefile'
COMMAND =
%w{rake rails}
PATH =
Pult::RAKEPATH || 'r'

Class Method Summary collapse

Class Method Details

.mixin!(panel) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/pult/panel/provider/rake.rb', line 8

def self.mixin! panel
  app_dirs = Pult::Panel::Provider.app_dirs(panel)

  app_dirs.map{|a, d| [a, "#{d}/#{FILE}"] }.each do |app, rake_file|
    hash = pult_hash rake_file

    panel[app]&.merge! hash
  end
end

.pult_hash(file) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pult/panel/provider/rake.rb', line 18

def self.pult_hash file
  hash  = {}

  maker = lambda do |task, command|
    n = -1
    task.split(':').reduce(hash) do |h, t|
      count = task.count(':')
      (n += 1) && n == count ? h[t] = "#{command} #{task}" : h[t] ||= {}
    end
  end

  for command in COMMAND
    tasks = self.tasks command, file

    tasks.sort.reverse.each{|task| maker.(task, command) }

    break if hash.any?
  end

  { PATH => hash }
end

.tasks(command, file) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pult/panel/provider/rake.rb', line 40

def self.tasks command, file
  app_dir = Pathname.new(file).dirname.to_s

  runner = Pult::Executor.run! "#{command} --tasks", app_dir

  tasks = runner[:stdout].split(/\n/).map do |s|
    s.sub(/^#{command} (\S+).*/, '\1')
  end

  # temp ignore params
  tasks.map{ |t| t.sub /\[.+/, '' }
end