Class: ModuleSync::Hook

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook_file, options = []) ⇒ Hook

Returns a new instance of Hook


7
8
9
10
11
12
# File 'lib/modulesync/hook.rb', line 7

def initialize(hook_file, options = [])
  @hook_file = hook_file
  @namespace = options['namespace']
  @branch = options['branch']
  @args = options['hook_args']
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


5
6
7
# File 'lib/modulesync/hook.rb', line 5

def args
  @args
end

#branchObject (readonly)

Returns the value of attribute branch


5
6
7
# File 'lib/modulesync/hook.rb', line 5

def branch
  @branch
end

#hook_fileObject (readonly)

Returns the value of attribute hook_file


5
6
7
# File 'lib/modulesync/hook.rb', line 5

def hook_file
  @hook_file
end

#namespaceObject (readonly)

Returns the value of attribute namespace


5
6
7
# File 'lib/modulesync/hook.rb', line 5

def namespace
  @namespace
end

Instance Method Details

#activateObject


25
26
27
28
29
30
31
32
33
34
# File 'lib/modulesync/hook.rb', line 25

def activate
  hook_args = []
  hook_args << "-n #{namespace}" if namespace
  hook_args << "-b #{branch}" if branch
  hook_args << args if args

  File.open(hook_file, 'w') do |file|
    file.write(content(hook_args.join(' ')))
  end
end

#content(arguments) ⇒ Object


14
15
16
17
18
19
20
21
22
23
# File 'lib/modulesync/hook.rb', line 14

def content(arguments)
  <<-EOF
#!/usr/bin/env bash

current_branch=\`git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,'\`
git_dir=\`git rev-parse --show-toplevel\`
message=\`git log -1 --format=%B\`
msync -m "\$message" #{arguments}
EOF
end

#deactivateObject


36
37
38
# File 'lib/modulesync/hook.rb', line 36

def deactivate
  File.delete(hook_file) if File.exist?(hook_file)
end