Class: VTools::Handler

Inherits:
Object
  • Object
show all
Includes:
SharedMethods
Defined in:
lib/vtools/handler.rb

Overview

hooks handler allows to execute hooks from external script multiple hooks in one placeholder are allowed

usage:

Handler.set :placeholder_name, &block

or

Handler.collection do
  set :placeholder_one, &block
  set :placeholder_other, &block
end

Class Method Summary collapse

Methods included from SharedMethods

included

Methods included from SharedMethods::Common

#config, #fix_encoding, #generate_path, #hash_to_obj, #json_to_obj, #keys_to_sym, #log, #logger=, #network_call, #parse_json, #path_generator

Class Method Details

.collection(&block) ⇒ Object

collection setup



38
39
40
# File 'lib/vtools/handler.rb', line 38

def collection &block
  instance_eval &block if block_given?
end

.exec(action, *args) ⇒ Object

pending hooks exectuion



30
31
32
33
34
35
# File 'lib/vtools/handler.rb', line 30

def exec action, *args
  action = action.to_sym
  @callbacks[action].each do |block|
    block.call(*args)
  end if @callbacks[action].is_a? Array
end

.set(action, &block) ⇒ Object

hooks setter



23
24
25
26
27
# File 'lib/vtools/handler.rb', line 23

def set action, &block
  action = action.to_sym
  @callbacks[action] = [] unless @callbacks[action].is_a? Array
  @callbacks[action] << block if block_given?
end