Class: Temp::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



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

def initialize(options = {})
  @conf_file = File.expand_path(options[:conf_file])
  @conf = { :template_dir => '~/.temp' }
  @args = options[:args] || {}

  if @conf_file && File.file?(@conf_file)
    @conf = YAML::load_file(@conf_file)
  else
    File.open(@conf_file, 'w') { |f| f.write(@conf.to_yaml) }
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



8
9
10
# File 'lib/temp/runner.rb', line 8

def args
  @args
end

#confObject (readonly)

Returns the value of attribute conf.



8
9
10
# File 'lib/temp/runner.rb', line 8

def conf
  @conf
end

#conf_fileObject (readonly)

Returns the value of attribute conf_file.



8
9
10
# File 'lib/temp/runner.rb', line 8

def conf_file
  @conf_file
end

Instance Method Details

#start!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/temp/runner.rb', line 22

def start!
  OptionParser.new do |o|
    o.banner = 'Usage: temp [options] [project] [template]'

    o.on('-v', '--version', 'Show version information') do
      puts "Temp #{Temp::VERSION}"
    end
  end.parse!(@args)

  c = Temp::Copier.new(:template_dir => @conf[:template_dir])
  if ARGV.size == 0
    raise 'no project directory or template name specified'
  elsif ARGV.size == 1
    c.create_project(ARGV[0])
  else
    c.create_project(ARGV[0], ARGV[1])
  end
rescue => e
  puts e.message
end