Class: GitHook::DSL
- Inherits:
-
Object
- Object
- GitHook::DSL
- Defined in:
- lib/git_hook/dsl.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#with_bundler ⇒ Object
readonly
Returns the value of attribute with_bundler.
Class Method Summary collapse
Instance Method Summary collapse
- #hook(name, timing, options = {}) ⇒ Object
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #load(path) ⇒ Object
- #with_bundler! ⇒ Object
Constructor Details
#initialize ⇒ DSL
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
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
15 16 17 |
# File 'lib/git_hook/dsl.rb', line 15 def hooks @hooks end |
#with_bundler ⇒ Object (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
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, = {}) timing = timing.to_s.to_sym = || {} @hooks[timing] = [] if @hooks[timing].nil? obj = GitHook::Hook.resolve(name) obj[:require] = [:require] if [: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] = @hooks[timing].push(obj) end |
#load(path) ⇒ Object
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 |