Class: Hookify::Command::Base
- Inherits:
-
Object
- Object
- Hookify::Command::Base
show all
- Includes:
- Helpers
- Defined in:
- lib/hookify/commands/base.rb
Instance Method Summary
collapse
Methods included from Helpers
#display, #error, #executable, #home_directory, #hooks_directory, #running_on_a_mac?, #running_on_windows?
Constructor Details
#initialize(args) ⇒ Base
Returns a new instance of Base.
5
6
7
|
# File 'lib/hookify/commands/base.rb', line 5
def initialize(args)
end
|
Instance Method Details
#command_name ⇒ Object
9
10
11
|
# File 'lib/hookify/commands/base.rb', line 9
def command_name
self.class.to_s.split("::").last.underscore
end
|
#file_name ⇒ Object
13
14
15
|
# File 'lib/hookify/commands/base.rb', line 13
def file_name
command_name.gsub("_", "-")
end
|
#file_path ⇒ Object
17
18
19
|
# File 'lib/hookify/commands/base.rb', line 17
def file_path
File.join(hooks_directory, file_name)
end
|
#remove_file ⇒ Object
29
30
31
|
# File 'lib/hookify/commands/base.rb', line 29
def remove_file
File.delete(file_path) if File.exists?(file_path)
end
|
#ruby_script_path ⇒ Object
21
22
23
|
# File 'lib/hookify/commands/base.rb', line 21
def ruby_script_path
"config/hooks/#{command_name}.rb"
end
|
#run ⇒ Object
25
26
27
|
# File 'lib/hookify/commands/base.rb', line 25
def run
end
|
#write_file ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/hookify/commands/base.rb', line 33
def write_file
script = IO.read(File.join(Hookify.root, "hooks/#{file_name}"))
remove_file already_exists = File.exists?(file_path)
unless already_exists
FileUtils.mkdir_p(hooks_directory)
File.new(file_path, "w")
end
FileUtils.mkdir_p(File.dirname(ruby_script_path))
File.new(ruby_script_path, "w") unless File.exists?(ruby_script_path)
display("Creating #{file_path}...\n")
File.open(file_path, "r+") do |file|
content = ""
content << script
file.pos = 0
file.print content
file.truncate(file.pos)
end
executable(file_path)
display("Add a rake task named 'hookify:#{command_name}'")
end
|