Class: EverydayPlugins::Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/everyday-plugins/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugins

Returns a new instance of Plugins.



32
33
34
35
36
# File 'lib/everyday-plugins/plugin.rb', line 32

def initialize
  @ext   = {}
  @types = {}
  @vars  = {}
end

Class Method Details

.get(type, *args) ⇒ Object



59
60
61
# File 'lib/everyday-plugins/plugin.rb', line 59

def self.get(type, *args)
  instance.get(type, *args)
end

.get_var(name) ⇒ Object



79
80
81
# File 'lib/everyday-plugins/plugin.rb', line 79

def self.get_var(name)
  instance.get_var(name)
end

.get_vars(*names) ⇒ Object



83
84
85
# File 'lib/everyday-plugins/plugin.rb', line 83

def self.get_vars(*names)
  instance.get_vars(*names)
end

.instanceObject



7
8
9
# File 'lib/everyday-plugins/plugin.rb', line 7

def self.instance
  @instance ||= Plugins.new
end

.load_plugins(path, error_fatal = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/everyday-plugins/plugin.rb', line 11

def self.load_plugins(path, error_fatal = false)
  begin
    Gem.find_latest_files("/#{path}/plugin/*.plugin.rb").each { |plugin|
      #noinspection RubyResolve
      begin
        require plugin
      rescue LoadError => e
        puts "Error in loading plugin '#{plugin}'"
        puts e.inspect
        puts e.backtrace.join("\n")
        exit 1 if error_fatal
      end
    }
  rescue Exception => e
    puts 'Error in loading plugins'
    puts e.inspect
    puts e.backtrace.join("\n")
    exit 1 if error_fatal
  end
end

.set_var(name, value) ⇒ Object



87
88
89
# File 'lib/everyday-plugins/plugin.rb', line 87

def self.set_var(name, value)
  instance.set_var(name, value)
end

.set_vars(vars = {}) ⇒ Object



91
92
93
# File 'lib/everyday-plugins/plugin.rb', line 91

def self.set_vars(vars = {})
  instance.set_vars(vars)
end

Instance Method Details

#[](type) ⇒ Object



51
52
53
# File 'lib/everyday-plugins/plugin.rb', line 51

def [](type)
  @ext[type] || []
end

#get(type, *args) ⇒ Object



55
56
57
# File 'lib/everyday-plugins/plugin.rb', line 55

def get(type, *args)
  @types[type].call(self[type], *args)
end

#get_var(name) ⇒ Object



63
64
65
# File 'lib/everyday-plugins/plugin.rb', line 63

def get_var(name)
  @vars[name] || nil
end

#get_vars(*names) ⇒ Object



67
68
69
# File 'lib/everyday-plugins/plugin.rb', line 67

def get_vars(*names)
  names.map { |name| get_var(name) }
end

#register(type, options = {}, &block) ⇒ Object



38
39
40
41
# File 'lib/everyday-plugins/plugin.rb', line 38

def register(type, options = {}, &block)
  @ext[type] ||= []
  @ext[type] << { options: options, block: block }
end

#register_type(type, &block) ⇒ Object



43
44
45
# File 'lib/everyday-plugins/plugin.rb', line 43

def register_type(type, &block)
  @types[type] = block
end

#register_variable(name, value = nil) ⇒ Object



47
48
49
# File 'lib/everyday-plugins/plugin.rb', line 47

def register_variable(name, value = nil)
  @vars[name] = value
end

#set_var(name, value) ⇒ Object



71
72
73
# File 'lib/everyday-plugins/plugin.rb', line 71

def set_var(name, value)
  @vars[name] = value
end

#set_vars(vars = {}) ⇒ Object



75
76
77
# File 'lib/everyday-plugins/plugin.rb', line 75

def set_vars(vars = {})
  vars.each { |v| set_var(*v) }
end