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, options = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/slnky/generator.rb', line 12

def initialize(name, options={})
  options = {
      force: false,
  }.merge(options)
  @name = name
  @service = "slnky-#{name}"
  @dir = File.expand_path("./#{@service}")
  short = self.class.name.split('::').last.downcase
  @template = File.expand_path("../template/#{short}", __FILE__)
  @force = options[:force]
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#generateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slnky/generator.rb', line 24

def generate
  say "<%= color('generating service #{@name}', BOLD) %>"
  # puts "  from: #{@template}"
  # puts "  to:   #{@dir}"
  process_files
  # git init
  if File.directory?("#{@dir}/.git")
    puts "git already initialized"
  else
    puts "initializing git..."
    `cd #{@dir} && git init . || true`
    `cd #{@dir} && git add .`
  end
end