Module: Kodiak

Defined in:
lib/kodiak.rb,
lib/kodiak/cli.rb,
lib/kodiak/utils.rb,
lib/kodiak/watcher.rb,
lib/kodiak/generator.rb,
lib/kodiak/transporter.rb,
lib/kodiak/notification.rb,
lib/kodiak/config_reader.rb

Defined Under Namespace

Classes: ConfigReader, Generator, Notification, Transporter, Watcher

Constant Summary collapse

APP_NAME =
"Kodiak"
VERSION =
"0.0.1"
ROOT_PATH =
Dir.pwd
CONFIG_PATH =
File.expand_path(File.dirname(__FILE__) + "/../config")
CONFIG_FILENAME =
"kodiak.yaml"
CONFIG_ICON =
"kodiak-icon.png"
USAGE_FILENAME =
"kodiak-usage.txt"
GLOBAL_CONFIG =
".kodiak_config"
LOG_FILENAME =
".kodiak_log"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#userObject

Returns the value of attribute user.



21
22
23
# File 'lib/kodiak.rb', line 21

def user
  @user
end

Class Method Details

.configure(options) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/kodiak/cli.rb', line 62

def self.configure(options)
	if not File.exists? "#{ENV['HOME']}/#{Kodiak::GLOBAL_CONFIG}"
		FileUtils.cp_r "#{Kodiak::CONFIG_PATH}/#{Kodiak::GLOBAL_CONFIG}", "#{ENV['HOME']}/#{Kodiak::GLOBAL_CONFIG}", :remove_destination => true
	end

	user = ""
	options.each do |key, value|
	  user += "#{key} : #{value}\n"
	end

	file = File.open("#{ENV['HOME']}/#{Kodiak::GLOBAL_CONFIG}", "w+")
	file.write(user)
	file.close

	Kodiak::Notification.new "Global configuration complete\n", "success"
	Kodiak::Notification.new "#{user}"
end

.log(params = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kodiak/utils.rb', line 3

def self.log(params={})
	pushed = params[:pushed]
	ignored = params[:ignored]

	file = File.open("#{Kodiak::LOG_FILENAME}", "a+")

  	time = Time.now.strftime("%A, %m/%d/%Y at %I:%M:%3N %p")
	message = "#{time} | #{Kodiak.user['name']} (#{Kodiak.user['email']})\n"
	message += "---------------------------------------------------------------------------------\n"
	message += "Pushed #{pushed.length} files and ignored #{ignored.length} files\n"
	message += "---------------------------------------------------------------------------------\n"
	
	pushed.each do |file|
		message += "Pushed [#{file[:source]}] --> [#{file[:destination]}]\n"			
	end
	
	ignored.each do |file|
		message += "Ignored #{file[:source]} because #{file[:reason].downcase}\n"			
	end		

	message += "\n\n\n"
	
	file.write(message)
	file.close
end

.push(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kodiak/cli.rb', line 3

def self.push(options)
	ARGV.shift

	if ! ARGV[0]
     Kodiak::Notification.new "Push requires an environment parameter\n", "failure"			
		puts "Example: 'kodiak push remote'"
		exit
	end

	options[:environment] = ARGV[0]
	config = Kodiak::ConfigReader.new(options)

	if options[:safe]
		continue = "yes"
	else
		puts "[environment = #{options[:environment]}]\n"
		puts "\nPush these files?"
		config.files.each do |file|
			puts "  - #{file[:source]} --> #{file[:destination]}"
		end
		puts "\nContinue? [yes|no]"
		continue = STDIN.gets.chomp
	end


	if continue =~ /([Yy][Ee][Ss]|[Yy]|1)/
		Kodiak::Transporter.new(config, options).transport
	else
		puts "Push canceled by user"
		exit
	end
end

.usageObject



92
93
94
95
96
# File 'lib/kodiak/cli.rb', line 92

def self.usage
  file = File.open("#{Kodiak::CONFIG_PATH}/#{Kodiak::USAGE_FILENAME}", 'r')
	puts file.read
	file.close
end

.userObject



27
28
29
# File 'lib/kodiak.rb', line 27

def self.user
	@user
end

.user=(user) ⇒ Object



23
24
25
# File 'lib/kodiak.rb', line 23

def self.user=(user)
	@user = user
end

.view_logObject



81
82
83
84
85
86
87
88
89
90
# File 'lib/kodiak/cli.rb', line 81

def self.view_log
	if not File.exists? Kodiak::LOG_FILENAME
		puts "Log file does not exist. Sorry."
		exit
	end
	
	file = File.open("#{Kodiak::LOG_FILENAME}", "r")
	puts file.read
	file.close
end

.watch(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kodiak/cli.rb', line 37

def self.watch(options)
	ARGV.shift

	if ! ARGV[0]
		puts "Watch requires an environment parameter"
		puts "Example: 'kodiak watch remote'"
		exit
	end

	options[:environment] = ARGV[0]
	config = Kodiak::ConfigReader.new(options)

	if options[:safe]
		continue = "yes"
	else
		puts "Start Kodiak server? [yes|no]"
		continue = STDIN.gets.chomp
	end

	if continue =~ /([Yy][Ee][Ss]|[Yy]|1)/
		Kodiak::Watcher.new(config, options)
	end
end