Class: Container::Templates::RakeTask

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/docker_rack/container_template.rb

Overview

< ::Rake::TaskLib

Constant Summary collapse

DEFAULT_PATTERN =

Default pattern for template files. DEFAULT_PATTERN = ‘container_templates/**,/<strong>/*</strong>/*.yml,yaml’

'**/*.{yml,yaml}'
DEFAULT_PATH =
'container_templates'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRakeTask

Returns a new instance of RakeTask.



38
39
40
41
42
43
44
45
46
# File 'lib/docker_rack/container_template.rb', line 38

def initialize
  options = Rake.application.options
  options.trace = false
  options.dryrun = false

  Rake::TaskManager. = true

  $environment = environment
end

Instance Attribute Details

#nameObject

Name of task. Defaults to ‘:container_templates`.



28
29
30
# File 'lib/docker_rack/container_template.rb', line 28

def name
  @name
end

#patternObject

Files matching this pattern will be loaded. Defaults to ‘’*/.yml,yaml‘`.



36
37
38
# File 'lib/docker_rack/container_template.rb', line 36

def pattern
  @pattern
end

#templates_pathObject

Path to Container templates. Defaults to the absolute path to the relative location of container templates.



32
33
34
# File 'lib/docker_rack/container_template.rb', line 32

def templates_path
  @templates_path
end

Instance Method Details

#contains?(task_name) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/docker_rack/container_template.rb', line 66

def contains?(task_name)
  tasks.any? { |task| task.name == task_name }
end

#environmentObject



74
75
76
77
78
79
# File 'lib/docker_rack/container_template.rb', line 74

def environment
  {
      dockerhost: Docker::Utils.dockerhost,
      work_dir: Environment.work_dir
  }
end

#invoke(name) ⇒ Object



70
71
72
# File 'lib/docker_rack/container_template.rb', line 70

def invoke(name)
  Rake.application[name].invoke
end

#process(params) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/docker_rack/container_template.rb', line 48

def process(params)
  @templates_path = params[:path] || DEFAULT_PATH
  @pattern        = params[:pattern] || DEFAULT_PATTERN

  load_templates @templates_path, @pattern

  scripts_path = File.join(@templates_path, 'scripts/*.rake')
  puts "Loading scripts from '#{scripts_path}'" if LOG_LEVEL == 'DEBUG'

  Dir.glob(scripts_path).each do |r|
    load r
  end
end

#tasksObject



62
63
64
# File 'lib/docker_rack/container_template.rb', line 62

def tasks
  Rake.application.tasks()
end