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
-
#version ⇒ Object
Installed version of this plugin’s gem, resolved from the Bundler spec via the registration callsite.
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
59 60 61 |
# File 'lib/avo/plugin.rb', line 59 def engine "#{namespace}::Engine".safe_constantize end |
.gemspec ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/avo/plugin.rb', line 69 def gemspec return if engine.blank? gemspec_path = Dir["#{engine.root}/*.gemspec"].first Gem::Specification.load(gemspec_path) end |
.name ⇒ Object
49 50 51 52 53 |
# File 'lib/avo/plugin.rb', line 49 def name return gemspec.name if gemspec.present? to_s.split("::").first end |
.namespace ⇒ Object
63 64 65 66 67 |
# File 'lib/avo/plugin.rb', line 63 def namespace modules = to_s.split("::") modules.pop modules.join("::") end |
.version ⇒ Object
55 56 57 |
# File 'lib/avo/plugin.rb', line 55 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 |
#version ⇒ Object
Installed version of this plugin’s gem, resolved from the Bundler spec via the registration callsite. Falls back to the class-level VERSION constant.
32 33 34 35 36 |
# File 'lib/avo/plugin.rb', line 32 def version return @version if defined?(@version) @version = registered_gem&.version&.to_s || self.class.version end |