Class: Kodiak::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Generator

Returns a new instance of Generator.



6
7
8
# File 'lib/kodiak/generator.rb', line 6

def initialize(options)
	@options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/kodiak/generator.rb', line 4

def options
  @options
end

Instance Method Details

#config_exists?Boolean

check to see if Kodiak.yaml already exists in directory

Returns:

  • (Boolean)


19
20
21
# File 'lib/kodiak/generator.rb', line 19

def config_exists?
	File.exists? Kodiak::CONFIG_FILENAME
end

#copy_configObject

copy sample Kodiak.yaml to directory



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

def copy_config
	FileUtils.cp_r "#{Kodiak::CONFIG_PATH}/#{Kodiak::CONFIG_FILENAME}", "#{Kodiak::CONFIG_FILENAME}", :remove_destination => true

	# if logs exist already, don't overwrite them. Not even in force mode. Never ever.
	if not File.exists? Kodiak::LOG_FILENAME
		FileUtils.cp_r "#{Kodiak::CONFIG_PATH}/#{Kodiak::LOG_FILENAME}", "#{Kodiak::LOG_FILENAME}", :remove_destination => true
	end

	Kodiak::Notification.new "Kodiak configuration created at #{Kodiak::CONFIG_FILENAME}\n", "success"
	system("open #{Kodiak::CONFIG_FILENAME}")
	exit
end

#generateObject



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

def generate
	if config_exists? && ! options[:force]
      Kodiak::Notification.new "Kodiak config already exists in this directory. Use --force to overwrite.\n", "failure"
	elsif (!config_exists?) || (config_exists? && options[:force])
		copy_config
	end
end