Class: GitoriousMuninPlugins::Plugin
- Inherits:
-
Object
- Object
- GitoriousMuninPlugins::Plugin
- Defined in:
- lib/gitorious-munin-plugins/plugin.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
-
.root ⇒ Object
Root of all plugins.
Instance Method Summary collapse
-
#binary ⇒ Object
The binary, used as a target for Munin symlinks.
- #description ⇒ Object
-
#initialize(name) ⇒ Plugin
constructor
A new instance of Plugin.
- #install! ⇒ Object
- #install_status ⇒ Object
-
#installed? ⇒ Boolean
Is there a symlink to us in /etc/munin/plugins ?.
- #named?(given) ⇒ Boolean
-
#target ⇒ Object
Where the symlink should be placed.
- #uninstall! ⇒ Object
Constructor Details
#initialize(name) ⇒ Plugin
Returns a new instance of Plugin.
46 47 48 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 46 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 45 def name @name end |
Class Method Details
.all ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 3 def self.all root.children.collect do |plugin| if plugin.basename.to_s.split(".").last == "rb" name = plugin.basename.to_s.sub(/\.rb/, "") new(name) end end.compact end |
.root ⇒ Object
Root of all plugins
13 14 15 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 13 def self.root Pathname(File.dirname(__FILE__)) + "plugins" end |
Instance Method Details
#binary ⇒ Object
The binary, used as a target for Munin symlinks
18 19 20 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 18 def binary Pathname(Gem.bindir) + "gitorious-munin-plugin" end |
#description ⇒ Object
67 68 69 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 67 def description "#{name} #{install_status}" end |
#install! ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 27 def install! if target.exist? puts "#{target} exists, ignoring" else puts "Installing #{target}" target.make_symlink(binary) end end |
#install_status ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 59 def install_status if installed? Term::ANSIColor.green {"(installed)"} else Term::ANSIColor.red {"(not installed)"} end end |
#installed? ⇒ Boolean
Is there a symlink to us in /etc/munin/plugins ?
51 52 53 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 51 def installed? File.exist?("/etc/munin/plugins/#{name}") end |
#named?(given) ⇒ Boolean
55 56 57 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 55 def named?(given) name == given end |
#target ⇒ Object
Where the symlink should be placed
23 24 25 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 23 def target Pathname("/etc/munin/plugins/#{name}") end |
#uninstall! ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/gitorious-munin-plugins/plugin.rb', line 36 def uninstall! if target.exist? puts "Deleting #{target}" target.delete else puts "#{target} exists" end end |