Sha256: e20f65c2d61a0ff8c7a2672aa285ff47a93bdb6c1841d95cfced0f86e119353a

Contents?: true

Size: 928 Bytes

Versions: 13

Compression:

Stored size: 928 Bytes

Contents

require 'modulesync'

module ModuleSync
  class Hook
    attr_reader :hook_file, :namespace, :branch, :args

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

    def content(arguments)
      <<-CONTENT
#!/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}
CONTENT
    end

    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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
modulesync-2.2.0 lib/modulesync/hook.rb
modulesync-2.1.1 lib/modulesync/hook.rb
modulesync-2.1.0 lib/modulesync/hook.rb
modulesync-2.0.2 lib/modulesync/hook.rb
modulesync-2.0.1 lib/modulesync/hook.rb
modulesync-2.0.0 lib/modulesync/hook.rb
modulesync-1.3.0 lib/modulesync/hook.rb
modulesync-1.2.0 lib/modulesync/hook.rb
modulesync-1.1.0 lib/modulesync/hook.rb
modulesync-1.0.0 lib/modulesync/hook.rb
modulesync-0.10.0 lib/modulesync/hook.rb
modulesync-0.9.0 lib/modulesync/hook.rb
modulesync-0.8.2 lib/modulesync/hook.rb