Class: Captify::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/captify/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(template_loader = TemplateLoader.new, kernel = Kernel) ⇒ Runner

Returns a new instance of Runner.



4
5
6
7
8
# File 'lib/captify/runner.rb', line 4

def initialize(template_loader=TemplateLoader.new, kernel=Kernel)
  @template_loader = template_loader
  @kernel = kernel
  @default_options = {:load_path_only => false}
end

Instance Method Details

#run(template_name, target_dir, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/captify/runner.rb', line 10

def run(template_name, target_dir, options={})
  raise ArgumentError, "'#{target_dir}' does not exist." unless File.exist? target_dir
  raise ArgumentError, "'#{target_dir}' is not a directory." unless File.directory? target_dir

  options = @default_options.merge(options)

  @template_loader.reload! options[:load_path_only]

  template = @template_loader.find(template_name)
  unless template
    raise ArgumentError, "template not found: '#{template_name}'"
  end

  @kernel.puts "[apply] template '#{template_name}'"

  logs = template.apply_to(target_dir)
  logs.each{|msg| @kernel.puts msg}

  @kernel.puts "[done] captified!"
end