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.



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

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

Class Method Details

.get(type, *args) ⇒ Object



57
58
59
# File 'lib/everyday-plugins/plugin.rb', line 57

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

.get_var(name) ⇒ Object



77
78
79
# File 'lib/everyday-plugins/plugin.rb', line 77

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

.get_vars(*names) ⇒ Object



81
82
83
# File 'lib/everyday-plugins/plugin.rb', line 81

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
# 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
        exit 1 if error_fatal
      end
    }
  rescue Exception => e
    puts 'Error in loading plugins'
    puts e.inspect
    exit 1 if error_fatal
  end
end

.set_var(name, value) ⇒ Object



85
86
87
# File 'lib/everyday-plugins/plugin.rb', line 85

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

.set_vars(vars = {}) ⇒ Object



89
90
91
# File 'lib/everyday-plugins/plugin.rb', line 89

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

Instance Method Details

#[](type) ⇒ Object



49
50
51
# File 'lib/everyday-plugins/plugin.rb', line 49

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

#get(type, *args) ⇒ Object



53
54
55
# File 'lib/everyday-plugins/plugin.rb', line 53

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

#get_var(name) ⇒ Object



61
62
63
# File 'lib/everyday-plugins/plugin.rb', line 61

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

#get_vars(*names) ⇒ Object



65
66
67
# File 'lib/everyday-plugins/plugin.rb', line 65

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

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



36
37
38
39
# File 'lib/everyday-plugins/plugin.rb', line 36

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

#register_type(type, &block) ⇒ Object



41
42
43
# File 'lib/everyday-plugins/plugin.rb', line 41

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

#register_variable(name, value = nil) ⇒ Object



45
46
47
# File 'lib/everyday-plugins/plugin.rb', line 45

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

#set_var(name, value) ⇒ Object



69
70
71
# File 'lib/everyday-plugins/plugin.rb', line 69

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

#set_vars(vars = {}) ⇒ Object



73
74
75
# File 'lib/everyday-plugins/plugin.rb', line 73

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