Class: ModuleSync::Hook
- Inherits:
-
Object
- Object
- ModuleSync::Hook
- Defined in:
- lib/modulesync/hook.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#hook_file ⇒ Object
readonly
Returns the value of attribute hook_file.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #activate ⇒ Object
- #content(arguments) ⇒ Object
- #deactivate ⇒ Object
-
#initialize(hook_file, options = []) ⇒ Hook
constructor
A new instance of Hook.
Constructor Details
#initialize(hook_file, options = []) ⇒ Hook
Returns a new instance of Hook.
9 10 11 12 13 14 |
# File 'lib/modulesync/hook.rb', line 9 def initialize(hook_file, = []) @hook_file = hook_file @namespace = [:namespace] @branch = [:branch] @args = [:hook_args] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/modulesync/hook.rb', line 7 def args @args end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
7 8 9 |
# File 'lib/modulesync/hook.rb', line 7 def branch @branch end |
#hook_file ⇒ Object (readonly)
Returns the value of attribute hook_file.
7 8 9 |
# File 'lib/modulesync/hook.rb', line 7 def hook_file @hook_file end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/modulesync/hook.rb', line 7 def namespace @namespace end |
Instance Method Details
#activate ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/modulesync/hook.rb', line 27 def activate hook_args = [] hook_args << "-n #{namespace}" if namespace hook_args << "-b #{branch}" if branch hook_args << args if args File.write(hook_file, content(hook_args.join(' '))) end |
#content(arguments) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/modulesync/hook.rb', line 16 def content(arguments) " #!/usr/bin/env bash\n\n current_branch=`git symbolic-ref HEAD | sed -e 's,.*/(.*),\\1,'`\n git_dir=`git rev-parse --show-toplevel`\n message=`git log -1 --format=%B`\n msync -m \"$message\" \#{arguments}\n CONTENT\nend\n" |
#deactivate ⇒ Object
36 37 38 |
# File 'lib/modulesync/hook.rb', line 36 def deactivate FileUtils.rm_f(hook_file) end |