Class: Dry::System::Plugins::Plugin Private
- Inherits:
-
Object
- Object
- Dry::System::Plugins::Plugin
- Defined in:
- lib/dry/system/plugins/plugin.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #block ⇒ Object readonly private
- #mod ⇒ Object readonly private
- #name ⇒ Object readonly private
Instance Method Summary collapse
- #apply_to(system, **options) ⇒ Object private
-
#initialize(name, mod, &block) ⇒ Plugin
constructor
private
A new instance of Plugin.
- #load_dependencies(dependencies = mod_dependencies, gem = nil) ⇒ Object private
- #load_dependency(dependency, gem) ⇒ Object private
- #mod_dependencies ⇒ Object private
- #stateful? ⇒ Boolean private
Constructor Details
#initialize(name, mod, &block) ⇒ Plugin
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Plugin.
15 16 17 18 19 |
# File 'lib/dry/system/plugins/plugin.rb', line 15 def initialize(name, mod, &block) @name = name @mod = mod @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/dry/system/plugins/plugin.rb', line 12 def block @block end |
#mod ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/dry/system/plugins/plugin.rb', line 10 def mod @mod end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/dry/system/plugins/plugin.rb', line 8 def name @name end |
Instance Method Details
#apply_to(system, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 |
# File 'lib/dry/system/plugins/plugin.rb', line 22 def apply_to(system, **) system.extend(stateful? ? mod.new(**) : mod) system.instance_eval(&block) if block system end |
#load_dependencies(dependencies = mod_dependencies, gem = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 34 35 36 37 |
# File 'lib/dry/system/plugins/plugin.rb', line 29 def load_dependencies(dependencies = mod_dependencies, gem = nil) Array(dependencies).each do |dependency| if dependency.is_a?(Array) || dependency.is_a?(Hash) dependency.each { |value| load_dependencies(*Array(value).reverse) } elsif !Plugins.loaded_dependencies.include?(dependency.to_s) load_dependency(dependency, gem) end end end |
#load_dependency(dependency, gem) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 |
# File 'lib/dry/system/plugins/plugin.rb', line 40 def load_dependency(dependency, gem) Kernel.require dependency Plugins.loaded_dependencies << dependency.to_s rescue LoadError => e raise PluginDependencyMissing.new(name, e., gem) end |
#mod_dependencies ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 |
# File 'lib/dry/system/plugins/plugin.rb', line 53 def mod_dependencies return EMPTY_ARRAY unless mod.respond_to?(:dependencies) mod.dependencies.is_a?(Array) ? mod.dependencies : [mod.dependencies] end |
#stateful? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/dry/system/plugins/plugin.rb', line 48 def stateful? mod < Module end |