Class: ROM::Plugin
Overview
Plugin is a simple object used to store plugin configurations
Constant Summary collapse
- INTERNAL_OPTS =
These opts are excluded when passing to mod's
apply
%i[enabled applied target].freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Symbol
readonly
Plugin adapter.
-
#config ⇒ Symbol
readonly
Plugin optional config.
-
#dsl ⇒ Module?
readonly
Optional DSL extensions.
-
#mod ⇒ Module
readonly
A module representing the plugin.
-
#name ⇒ Symbol
readonly
Plugin name.
-
#type ⇒ Symbol
readonly
Plugin type.
Instance Method Summary collapse
- #applied? ⇒ Boolean private
- #apply ⇒ Object private
-
#configure(**options) {|plugin.config| ... } ⇒ Object
Configure plugin.
- #dup ⇒ Object private
- #enable(target) ⇒ Object private
- #enabled? ⇒ Boolean private
-
#key ⇒ String
private
Plugin registry key.
- #plugin_options ⇒ Object private
Instance Attribute Details
#adapter ⇒ Symbol (readonly)
Returns plugin adapter.
32 |
# File 'lib/rom/plugin.rb', line 32 option :adapter, optional: true |
#config ⇒ Symbol (readonly)
Returns Plugin optional config.
36 |
# File 'lib/rom/plugin.rb', line 36 option :config, default: -> { ROM::OpenStruct.new } |
#dsl ⇒ Module? (readonly)
Returns Optional DSL extensions.
40 |
# File 'lib/rom/plugin.rb', line 40 option :dsl, default: -> { mod.const_defined?(:DSL) ? mod.const_get(:DSL) : nil } |
#mod ⇒ Module (readonly)
Returns a module representing the plugin.
27 |
# File 'lib/rom/plugin.rb', line 27 option :mod |
#name ⇒ Symbol (readonly)
Returns plugin name.
22 |
# File 'lib/rom/plugin.rb', line 22 option :name |
#type ⇒ Symbol (readonly)
Returns plugin type.
17 |
# File 'lib/rom/plugin.rb', line 17 option :type |
Instance Method Details
#applied? ⇒ 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.
96 97 98 |
# File 'lib/rom/plugin.rb', line 96 def applied? config.key?(:applied) && config.applied == true end |
#apply ⇒ 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.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rom/plugin.rb', line 78 def apply if enabled? apply_to(config.target, **) config.applied = true config.freeze freeze self else raise "Cannot apply a plugin because it was not enabled for any target" end end |
#configure(**options) {|plugin.config| ... } ⇒ Object
Configure plugin
57 58 59 60 61 62 |
# File 'lib/rom/plugin.rb', line 57 def configure(**) plugin = dup plugin.config.update() yield(plugin.config) if block_given? plugin end |
#dup ⇒ 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.
65 66 67 |
# File 'lib/rom/plugin.rb', line 65 def dup with(config: ROM::OpenStruct.new(config.to_h.clone)) end |
#enable(target) ⇒ 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.
70 71 72 73 74 75 |
# File 'lib/rom/plugin.rb', line 70 def enable(target) target.extend(dsl) if dsl config.enabled = true config.target = target self end |
#enabled? ⇒ 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.
91 92 93 |
# File 'lib/rom/plugin.rb', line 91 def enabled? config.key?(:enabled) && config.enabled == true end |
#key ⇒ String
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.
Plugin registry key
50 51 52 |
# File 'lib/rom/plugin.rb', line 50 def key [adapter, type, name].compact.join(".") end |
#plugin_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.
101 102 103 |
# File 'lib/rom/plugin.rb', line 101 def (opts = config.to_h).slice(*(opts.keys - INTERNAL_OPTS)) end |