Class: Avo::Plugin
- Inherits:
-
Object
- Object
- Avo::Plugin
- Defined in:
- lib/avo/plugin.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#registered_from ⇒ Object
readonly
Returns the value of attribute registered_from.
Class Method Summary collapse
Instance Method Summary collapse
-
#gem_name ⇒ Object
The real gem name this plugin ships in (e.g. ‘avo-rhino_field`), as opposed to the nickname it registered under (e.g. `:rhino`).
-
#initialize(name:, priority:, registered_from: nil, &block) ⇒ Plugin
constructor
A new instance of Plugin.
- #to_s ⇒ Object
Constructor Details
#initialize(name:, priority:, registered_from: nil, &block) ⇒ Plugin
Returns a new instance of Plugin.
9 10 11 12 13 |
# File 'lib/avo/plugin.rb', line 9 def initialize(*, name:, priority:, registered_from: nil, **, &block) @name = name @priority = priority @registered_from = registered_from end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/avo/plugin.rb', line 3 def name @name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
4 5 6 |
# File 'lib/avo/plugin.rb', line 4 def priority @priority end |
#registered_from ⇒ Object (readonly)
Returns the value of attribute registered_from.
5 6 7 |
# File 'lib/avo/plugin.rb', line 5 def registered_from @registered_from end |
Class Method Details
.engine ⇒ Object
51 52 53 |
# File 'lib/avo/plugin.rb', line 51 def engine "#{namespace}::Engine".safe_constantize end |
.gemspec ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/avo/plugin.rb', line 61 def gemspec return if engine.blank? gemspec_path = Dir["#{engine.root}/*.gemspec"].first Gem::Specification.load(gemspec_path) end |
.name ⇒ Object
41 42 43 44 45 |
# File 'lib/avo/plugin.rb', line 41 def name return gemspec.name if gemspec.present? to_s.split("::").first end |
.namespace ⇒ Object
55 56 57 58 59 |
# File 'lib/avo/plugin.rb', line 55 def namespace modules = to_s.split("::") modules.pop modules.join("::") end |
.version ⇒ Object
47 48 49 |
# File 'lib/avo/plugin.rb', line 47 def version "#{namespace}::VERSION".safe_constantize end |
Instance Method Details
#gem_name ⇒ Object
The real gem name this plugin ships in (e.g. ‘avo-rhino_field`), as opposed to the nickname it registered under (e.g. `:rhino`). Resolved by matching the file that called `register` against the gems in the bundle, so it works no matter how the plugin registered and even when the gem isn’t ‘avo-*`. Returns nil when the owning gem can’t be found in the bundle.
24 25 26 27 28 |
# File 'lib/avo/plugin.rb', line 24 def gem_name return @gem_name if defined?(@gem_name) @gem_name = registered_gem&.name end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/avo/plugin.rb', line 15 def to_s "#{name}-#{version}" end |