module Conf
Constants
- MAIN_CALLS
- SUB_CALLS
Public Class Methods
included(base)
click to toggle source
# File lib/bleetz/conf.rb, line 25 def self.included(base) base.extend(self) end
Public Instance Methods
action(action, desc = "") { || ... }
click to toggle source
# 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) { || ... }
click to toggle source
# 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) { || ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/bleetz/conf.rb, line 78 def set(opt, value) check_call(:set) @@options[opt.to_sym] = value end
shell(cmd)
click to toggle source
# 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
Private Instance Methods
check_call(func)
click to toggle source
# File lib/bleetz/conf.rb, line 85 def check_call(func) if MAIN_CALLS[:func].include?(func.to_s) parent_call = caller[2][/`([^']*)'/, 1] unless MAIN_CALLS[:from].include?(parent_call) raise "#{caller[1].split(" ")[0]} '#{func}'. Main functions cannot be called in functions." end else parent_call = caller[4][/`([^']*)'/, 1] unless SUB_CALLS[func].include?(parent_call) raise "#{caller[1].split(" ")[0]} #{SUB_CALLS[:error][func]}" end end end
load_conf() { || ... }
click to toggle source
# File lib/bleetz/conf.rb, line 99 def load_conf @after = @cmds = @before = [] begin yield rescue Exception => e if e.class.eql? RuntimeError raise BleetzException.new(e.message) else raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}") end end end