Class: Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/dot_example/hook.rb

Direct Known Subclasses

PostCheckoutHook, PreCommitHook

Instance Method Summary collapse

Instance Method Details

#contains_steps?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dot_example/hook.rb', line 42

def contains_steps?
  contents.include?(steps)
end

#contentsObject



10
11
12
# File 'lib/dot_example/hook.rb', line 10

def contents
  File.read(filepath)
end

#create_fileObject



24
25
26
27
28
# File 'lib/dot_example/hook.rb', line 24

def create_file
  %x[ touch #{filepath} ]
  %x[ chmod +x #{filepath} ]
  print_new_hook_message
end

#create_file_if_does_not_existObject



18
19
20
21
22
# File 'lib/dot_example/hook.rb', line 18

def create_file_if_does_not_exist
  unless Dir.glob(filepath).any?
    create_file
  end
end

#filepathObject



14
15
16
# File 'lib/dot_example/hook.rb', line 14

def filepath
  File.join(".git", "hooks", type)
end

#find_or_createObject



30
31
# File 'lib/dot_example/hook.rb', line 30

def find_or_create
end


2
3
4
# File 'lib/dot_example/hook.rb', line 2

def print_new_hook_message
  puts Paint["New #{type} hook created", :green]
end


6
7
8
# File 'lib/dot_example/hook.rb', line 6

def print_new_steps_message
  puts Paint[ "New steps added to #{type} hook\n#{steps}", :green]
end

#write!Object



33
34
35
36
37
38
39
40
# File 'lib/dot_example/hook.rb', line 33

def write!
  unless contains_steps? 
    File.open(filepath, "a") do |file|
      file.puts steps
    end
    print_new_steps_message
  end
end