Module: Conf

Included in:
Object
Defined in:
lib/bleetz/conf.rb

Constant Summary collapse

MAIN_CALLS =
{:func => ['action', 'before', 'after', 'set'],
:from => ['load']}
SUB_CALLS =
{:shell => ['action', 'before', 'after'],
                :call => ['action'],
                :error => { :shell => "'shell'. 'shell' has to be called in 'action', 'before' or 'after' functions.",
:call => "'call'. 'call' has to be called in 'action' function."} }
@@before =
{}
@@actions =
{}
@@after =
{}
@@tasks =
{}
@@options =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
# File 'lib/bleetz/conf.rb', line 25

def self.included(base)
  base.extend(self)
end

Instance Method Details

#action(action, desc = "") ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/bleetz/conf.rb', line 29

def action(action, desc = "")
  check_call(:action)
  load_conf { yield }
  h = { action.to_sym => @cmds }
  t = { action.to_sym => desc.to_s }
  @@actions = @@actions.merge(h)
  @@tasks = @@tasks.merge(t)
end

#after(action) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/bleetz/conf.rb', line 49

def after(action)
  check_call(:after)
  load_conf { yield }
  h = { action.to_sym => @after }
  if @@before[action.to_sym].nil?
    @@after = @@after.merge(h)
  else
    raise "You specified two 'after' callbacks for :#{action} action."
  end
end

#before(action) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/bleetz/conf.rb', line 38

def before(action)
  check_call(:before)
  load_conf { yield }
  h = { action.to_sym => @before }
  if @@before[action.to_sym].nil?
    @@before = @@before.merge(h)
  else
    raise "You specified two 'before' callbacks for :#{action} action."
  end
end

#call(action) ⇒ Object



72
73
74
75
76
# File 'lib/bleetz/conf.rb', line 72

def call(action)
  check_call(:call)
  raise "'call :action_name'. You didn't pass a Symbol." unless action.is_a? Symbol
  @cmds << action
end

#set(opt, value) ⇒ Object



78
79
80
81
# File 'lib/bleetz/conf.rb', line 78

def set(opt, value)
  check_call(:set)
  @@options[opt.to_sym] = value
end

#shell(cmd) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bleetz/conf.rb', line 60

def shell(cmd)
  check_call(:shell)
  raise "'shell' needs a String as parameter." unless cmd.is_a? String
  if caller[1][/`([^']*)'/, 1].eql?("action")
    @cmds << cmd
  elsif caller[1][/`([^']*)'/, 1].eql?("before")
    @before << cmd
  else
    @after << cmd
  end
end