Class: Slnky::Generator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/slnky/generator.rb

Direct Known Subclasses

Command, Service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dir) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
# File 'lib/slnky/generator.rb', line 11

def initialize(name, dir)
  @name = name
  @dir = dir == nil ? "slnky-#{name}" : dir
  short = self.class.name.split('::').last.downcase
  @template = File.expand_path("../template/#{short}", __FILE__)
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/slnky/generator.rb', line 9

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/slnky/generator.rb', line 8

def name
  @name
end

Instance Method Details

#generateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/slnky/generator.rb', line 18

def generate
  # copy dir
  puts "creating directory and processing templates..."
  FileUtils.cp_r(@template, @dir)
  puts "#{@dir}:"
  # process templates
  Find.find(@dir).each do |f|
    next unless File.file?(f) && File.extname(f) == '.erb'
    template(f)
  end
  # make service executable
  `chmod 755 #{@dir}/service-slnky-#{@name}`
  # git init
  puts "initializing git..."
  `cd #{@dir} && git init . || true`
end