Class: Avo::PluginManager

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/plugin_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePluginManager

Returns a new instance of PluginManager.



7
8
9
# File 'lib/avo/plugin_manager.rb', line 7

def initialize
  @plugins = []
end

Instance Attribute Details

#pluginsObject (readonly) Also known as: all

Returns the value of attribute plugins.



3
4
5
# File 'lib/avo/plugin_manager.rb', line 3

def plugins
  @plugins
end

Instance Method Details

#as_json(*arg) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/avo/plugin_manager.rb', line 31

def as_json(*arg)
  plugins.map do |plugin|
    {
      klass: plugin.to_s,
      priority: plugin.priority,
    }
  end
end

#installed?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/avo/plugin_manager.rb', line 48

def installed?(name)
  plugins.any? do |plugin|
    plugin.name.to_s == name.to_s
  end
end

#register(name, priority: 10) ⇒ Object



11
12
13
# File 'lib/avo/plugin_manager.rb', line 11

def register(name, priority: 10)
  @plugins << Plugin.new(name:, priority: priority)
end

#register_field(method_name, klass) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/avo/plugin_manager.rb', line 15

def register_field(method_name, klass)
  # Avo.boot method is executed multiple times.
  # During the first run, it correctly loads descendants of Avo::Fields::Base.
  # Plugins are then loaded, introducing additional descendants to Avo::Fields::Base.
  # On subsequent runs, Avo::Fields::Base descendants now include these plugin fields.
  # This field_name_attribute assign forces the field name to retain the registered name instead of being computed dynamically from the field class.
  klass.field_name_attribute = method_name
  Avo.field_manager.load_field method_name, klass
end

#register_resource_toolObject



25
26
# File 'lib/avo/plugin_manager.rb', line 25

def register_resource_tool
end

#register_toolObject



28
29
# File 'lib/avo/plugin_manager.rb', line 28

def register_tool
end

#to_sObject



40
41
42
43
44
45
46
# File 'lib/avo/plugin_manager.rb', line 40

def to_s
  plugins.map do |plugin|
    plugin.to_s
  end.join(",")
rescue
  "Failed to fetch plugins."
end