Class: Pry::PluginManager::Plugin
Instance Attribute Summary collapse
-
#active ⇒ Object
(also: #active?)
Returns the value of attribute active.
-
#enabled ⇒ Object
(also: #enabled?)
Returns the value of attribute enabled.
-
#gem_name ⇒ Object
Returns the value of attribute gem_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#spec ⇒ Object
Returns the value of attribute spec.
Instance Method Summary collapse
-
#activate! ⇒ Object
Activate the plugin (require the gem - enables/loads the plugin immediately at point of call, even if plugin is disabled) Does not reload plugin if it’s already active.
-
#disable! ⇒ Object
Disable a plugin.
-
#enable! ⇒ Object
Enable a plugin.
-
#initialize(name, gem_name, spec, enabled) ⇒ Plugin
constructor
A new instance of Plugin.
-
#load_cli_options ⇒ Object
Load the Command line options defined by this plugin (if they exist).
- #supported? ⇒ Boolean
Constructor Details
#initialize(name, gem_name, spec, enabled) ⇒ Plugin
Returns a new instance of Plugin.
28 29 30 31 32 33 |
# File 'lib/pry/plugins.rb', line 28 def initialize(name, gem_name, spec, enabled) @name = name @gem_name = gem_name @enabled = enabled @spec = spec end |
Instance Attribute Details
#active ⇒ Object Also known as: active?
Returns the value of attribute active.
26 27 28 |
# File 'lib/pry/plugins.rb', line 26 def active @active end |
#enabled ⇒ Object Also known as: enabled?
Returns the value of attribute enabled.
26 27 28 |
# File 'lib/pry/plugins.rb', line 26 def enabled @enabled end |
#gem_name ⇒ Object
Returns the value of attribute gem_name.
26 27 28 |
# File 'lib/pry/plugins.rb', line 26 def gem_name @gem_name end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/pry/plugins.rb', line 26 def name @name end |
#spec ⇒ Object
Returns the value of attribute spec.
26 27 28 |
# File 'lib/pry/plugins.rb', line 26 def spec @spec end |
Instance Method Details
#activate! ⇒ Object
Activate the plugin (require the gem - enables/loads the plugin immediately at point of call, even if plugin is disabled) Does not reload plugin if it’s already active.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pry/plugins.rb', line 62 def activate! # Create the configuration object for the plugin. Pry.config.send("#{gem_name.tr('-', '_')}=", OpenStruct.new) begin require gem_name unless active? rescue LoadError => e warn "Found plugin #{gem_name}, but could not require '#{gem_name}'" warn e rescue StandardError => e warn "require '#{gem_name}' # Failed, saying: #{e}" end self.active = true self.enabled = true end |
#disable! ⇒ Object
Disable a plugin. (prevents plugin from being loaded, cannot disable an already activated plugin)
37 38 39 |
# File 'lib/pry/plugins.rb', line 37 def disable! self.enabled = false end |
#enable! ⇒ Object
Enable a plugin. (does not load it immediately but puts on ‘white list’ to be loaded)
43 44 45 |
# File 'lib/pry/plugins.rb', line 43 def enable! self.enabled = true end |
#load_cli_options ⇒ Object
Load the Command line options defined by this plugin (if they exist)
48 49 50 51 52 53 54 55 56 |
# File 'lib/pry/plugins.rb', line 48 def = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb") return unless File.exist?() if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4") = File.realpath() end require end |
#supported? ⇒ Boolean
82 83 84 85 86 87 88 89 90 |
# File 'lib/pry/plugins.rb', line 82 def supported? pry_version = Gem::Version.new(VERSION) spec.dependencies.each do |dependency| if dependency.name == "pry" return dependency.requirement.satisfied_by?(pry_version) end end true end |