Class: GitHook::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/git_hook/dsl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



11
12
13
14
# File 'lib/git_hook/dsl.rb', line 11

def initialize
  @hooks = {}
  @with_bundler = false
end

Instance Attribute Details

#hooksObject (readonly)

Returns the value of attribute hooks.



15
16
17
# File 'lib/git_hook/dsl.rb', line 15

def hooks
  @hooks
end

#with_bundlerObject (readonly)

Returns the value of attribute with_bundler.



15
16
17
# File 'lib/git_hook/dsl.rb', line 15

def with_bundler
  @with_bundler
end

Class Method Details

.eval(hooks_file) ⇒ Object



5
6
7
8
9
# File 'lib/git_hook/dsl.rb', line 5

def self.eval(hooks_file)
  env = new
  env.load(hooks_file)
  env
end

Instance Method Details

#hook(name, timing, options = {}) ⇒ Object

Parameters:

  • name (String, Symbol, Class)
  • timing (Symbol)

    GitHook::Timings

  • options (Hash) (defaults to: {})

Options Hash (options):

  • gem (String)

    require path



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/git_hook/dsl.rb', line 25

def hook(name, timing, options = {})
  timing = timing.to_s.to_sym
  options = options || {}
  @hooks[timing] = [] if @hooks[timing].nil?

  obj = GitHook::Hook.resolve(name)
  obj[:require] = options[:require] if options[:require]
  Kernel.instance_eval do
    begin
      require obj[:require]
    rescue LoadError
    end
  end
  obj[:class] = obj[:class].to_s.split('::').inject(Kernel){|namespace, klass|
    namespace.const_get(klass)
  }
  obj[:options] = options

  @hooks[timing].push(obj)
end

#load(path) ⇒ Object

Parameters:

  • path (String)


53
54
55
# File 'lib/git_hook/dsl.rb', line 53

def load(path)
  instance_eval(open(path){|f| f.read })
end

#with_bundler!Object



17
18
19
# File 'lib/git_hook/dsl.rb', line 17

def with_bundler!
  @with_bundler = true
end