Module: Watobo::EgressHandlers

Defined in:
lib/watobo/core/egress_handlers.rb

Overview

:nodoc: all

Constant Summary collapse

CONFIG_FILE =
'egress_config.yml'
MAX_HISTORY =
5

Class Method Summary collapse

Class Method Details

.add(file) ⇒ Object



19
20
21
22
23
# File 'lib/watobo/core/egress_handlers.rb', line 19

def self.add(file)
  load file
  update
  save_config
end

.create(name) ⇒ Object



34
35
36
37
38
39
# File 'lib/watobo/core/egress_handlers.rb', line 34

def self.create(name)
#      puts "create egress-handler #{name}" 
  fkey = name.to_sym
  return nil unless @handlers.has_key? fkey
  @handlers[fkey].new()
end

.initObject



75
76
77
78
# File 'lib/watobo/core/egress_handlers.rb', line 75

def self.init
  @cfg_file = File.join Watobo.working_directory, 'conf', CONFIG_FILE
  load_config
end

.lastObject



25
26
27
# File 'lib/watobo/core/egress_handlers.rb', line 25

def self.last
  @last
end

.last=(name) ⇒ Object



29
30
31
32
# File 'lib/watobo/core/egress_handlers.rb', line 29

def self.last=(name)
  @last = name
  save_config
end

.lengthObject



51
52
53
# File 'lib/watobo/core/egress_handlers.rb', line 51

def self.length
  @handlers.length
end

.list(&block) ⇒ Object



12
13
14
15
16
17
# File 'lib/watobo/core/egress_handlers.rb', line 12

def self.list(&block)
  @handlers.each_key do |name|
    yield name if block_given?
  end
  @handlers.each_key.to_a
end

.load(file) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/watobo/core/egress_handlers.rb', line 61

def self.load(file)
  begin
    Kernel.load file
    @history << file
    @history.uniq!
    @history.shift if @history.length > MAX_HISTORY

  rescue SyntaxError => bang
    puts bang
    puts bang.backtrace
  end

end

.load_configObject



80
81
82
83
84
85
86
87
# File 'lib/watobo/core/egress_handlers.rb', line 80

def self.load_config
  cfg = Watobo::DataStore.load_project_settings(self.name.gsub(/^.*::/,''))
  return false if cfg.nil?
  @last = cfg[:last]
  @history = cfg[:history]
  reload
  update
end

.reloadObject



55
56
57
58
59
# File 'lib/watobo/core/egress_handlers.rb', line 55

def self.reload
  @history.each do |file|
    load file
  end
end

.save_configObject



89
90
91
92
93
94
95
# File 'lib/watobo/core/egress_handlers.rb', line 89

def self.save_config
  cfg = { :last => @last,
    :history => @history
  }
  Watobo::DataStore.save_project_settings(self.name.gsub(/^.*::/,''), cfg)
  
end

.updateObject



41
42
43
44
45
46
47
48
49
# File 'lib/watobo/core/egress_handlers.rb', line 41

def self.update
  constants.each do |name|
    next if name == :CONFIG_FILE
    next if name == :MAX_HISTORY
    h = class_eval(name.to_s)
    h_name = h.name.gsub(/.*::/, '').to_sym
    @handlers[h_name] = h
  end
end