module Dry::Plugins::Host::DSL
Mixin used as the DSL
of the host class or module
Public Instance Methods
inherited(child)
click to toggle source
Calls superclass method
# File lib/dry/plugins/host/dsl.rb, line 81 def inherited(child) super(child) child.instance_variable_set :@used_plugins, used_plugins.dup end
plugins(&block)
click to toggle source
@return [Module, DSL]
# File lib/dry/plugins/host/dsl.rb, line 75 def plugins(&block) plugins = const_get(Plugins.config.plugins_module_name) return plugins.module_eval(&block) if block_given? plugins end
use(*names, &configuration)
click to toggle source
(Auto)load the plugin called `name` and apply it to `host`
In case plugin `name` is not registered yet, registry will try to {Resolver#call resolve that plugin} by `name`
@param name [Symbol] @param configuration [Proc] optional configuration block
@return [<Symbol>] names of the currently used plugins
@example
class Resource extend Dry::Plugins module Plugins module Persistence def persist(something) STDOUT.puts "#{something} persisted!" end end register :persistence, Persistence end end class ArticleResource < Resource use :persistence #=> %i[persistence] end article = ArticleResource.new article.persist(:something) # prints `something persisted!`
# File lib/dry/plugins/host/dsl.rb, line 42 def use(*names, &configuration) names.map do |name| plugin = plugins.plugins_registry.resolve(name) plugin.call(self, &configuration) end end
used_plugins()
click to toggle source
@return [<Symbol>]
@example
class Resource extend Dry::Plugins module Plugins module Persistence def persist(something) STDOUT.puts "#{something} persisted!" end end register :persistence, Persistence end end class ArticleResource < Resource use :persistence #=> %i[persistence] used_plugins #=> %i[persistence] end
# File lib/dry/plugins/host/dsl.rb, line 70 def used_plugins @used_plugins ||= Set.new end