Class: VPM::Plugins
- Inherits:
-
Object
- Object
- VPM::Plugins
- Defined in:
- lib/vpm/plugins.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#installed_plugins ⇒ Object
readonly
Returns the value of attribute installed_plugins.
-
#removed_plugins ⇒ Object
readonly
Returns the value of attribute removed_plugins.
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #dump(io = nil) ⇒ Object
-
#initialize ⇒ Plugins
constructor
A new instance of Plugins.
- #installed?(plugin_name) ⇒ Boolean
- #load(content) ⇒ Object
- #plugin_installed(plugin) ⇒ Object
- #plugin_removed(plugin) ⇒ Object
- #save_to_file(file_path = VPM.plugins_file) ⇒ Object
Constructor Details
#initialize ⇒ Plugins
Returns a new instance of Plugins.
7 8 9 10 11 |
# File 'lib/vpm/plugins.rb', line 7 def initialize @all = [] @installed_plugins = [] @removed_plugins = [] end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
5 6 7 |
# File 'lib/vpm/plugins.rb', line 5 def all @all end |
#installed_plugins ⇒ Object (readonly)
Returns the value of attribute installed_plugins.
5 6 7 |
# File 'lib/vpm/plugins.rb', line 5 def installed_plugins @installed_plugins end |
#removed_plugins ⇒ Object (readonly)
Returns the value of attribute removed_plugins.
5 6 7 |
# File 'lib/vpm/plugins.rb', line 5 def removed_plugins @removed_plugins end |
Class Method Details
.load_from_file(file_path) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/vpm/plugins.rb', line 40 def self.load_from_file(file_path) plugins = self.new File.open(file_path) do |f| plugins.load(f) end plugins end |
Instance Method Details
#changed? ⇒ Boolean
17 18 19 |
# File 'lib/vpm/plugins.rb', line 17 def changed? installed_plugins.any? || removed_plugins.any? end |
#dump(io = nil) ⇒ Object
36 37 38 |
# File 'lib/vpm/plugins.rb', line 36 def dump(io = nil) YAML.dump(@all.collect(&:to_hash), io) end |
#installed?(plugin_name) ⇒ Boolean
13 14 15 |
# File 'lib/vpm/plugins.rb', line 13 def installed?(plugin_name) all.find { |p| p.name == plugin_name } end |
#load(content) ⇒ Object
31 32 33 34 |
# File 'lib/vpm/plugins.rb', line 31 def load(content) deserialized_content = YAML::load(content) @all = deserialized_content ? deserialized_content.collect { |hash| Plugin.from_hash(hash) } : [] end |
#plugin_installed(plugin) ⇒ Object
21 22 23 24 |
# File 'lib/vpm/plugins.rb', line 21 def plugin_installed(plugin) all << plugin installed_plugins << plugin end |
#plugin_removed(plugin) ⇒ Object
26 27 28 29 |
# File 'lib/vpm/plugins.rb', line 26 def plugin_removed(plugin) all.delete(plugin) removed_plugins << plugin end |
#save_to_file(file_path = VPM.plugins_file) ⇒ Object
49 50 51 52 53 |
# File 'lib/vpm/plugins.rb', line 49 def save_to_file(file_path = VPM.plugins_file) File.open(file_path, 'w' ) do |out| dump(out) end end |