Class: Minfra::Cli::Plugins::Plugin
- Inherits:
-
Object
- Object
- Minfra::Cli::Plugins::Plugin
- Includes:
- Logging
- Defined in:
- lib/minfra/cli/plugin.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #disabled? ⇒ Boolean
-
#initialize(name:, version:, opts:, disabled:) ⇒ Plugin
constructor
A new instance of Plugin.
- #install ⇒ Object
-
#prepare ⇒ Object
adds the plugin to the.
- #setup ⇒ Object
Methods included from Logging
#debug, #deprecated, #error, #exit_error, #info, #warn
Constructor Details
#initialize(name:, version:, opts:, disabled:) ⇒ Plugin
Returns a new instance of Plugin.
10 11 12 13 14 15 16 17 18 |
# File 'lib/minfra/cli/plugin.rb', line 10 def initialize(name:, version:, opts:, disabled:) @name = name @version = version @opts = opts.merge(require: false) @disabled = disabled return unless opts['path'] @path = Minfra::Cli.config.base_path.join(opts['path']) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/minfra/cli/plugin.rb', line 8 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/minfra/cli/plugin.rb', line 8 def opts @opts end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/minfra/cli/plugin.rb', line 8 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/minfra/cli/plugin.rb', line 8 def version @version end |
Instance Method Details
#disabled? ⇒ Boolean
20 21 22 |
# File 'lib/minfra/cli/plugin.rb', line 20 def disabled? @disabled end |
#install ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/minfra/cli/plugin.rb', line 24 def install if path system("cd #{path}; bundle install") else system("gem install #{name} --version #{version}") end end |
#prepare ⇒ Object
adds the plugin to the
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/minfra/cli/plugin.rb', line 33 def prepare debug("plugin prepare: #{name}, #{version}, disabled: #{disabled?}") return if disabled? if path begin lib_path = path.join('lib') $LOAD_PATH.unshift lib_path require name rescue Gem::Requirement::BadRequirementError, LoadError warn("plugin prepare path: #{name} (#{$ERROR_INFO})") end else begin @gem_spec = Gem::Specification.find_by_name(name) gem name, version rescue Gem::MissingSpecError warn("plugin prepare gem: #{name}, #{version} (#{$ERROR_INFO})") end end end |
#setup ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/minfra/cli/plugin.rb', line 55 def setup return if disabled? if path minfra_path = Pathname.new(path).join('minfracs', 'init.rb') if minfra_path.exist? begin require minfra_path # this should register the command rescue LoadError logger.warn("Minfra plugin detected but dependencies not installed: #{minfra_path} (#{$ERROR_INFO}). TRY: minfra plugin install") end end else error('Gem based plugins not supported yet') end end |