Sha256: 673c8996e1db48a911e063d4a8dee95e73702fd2625636e355fe310897808e2e

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

module Gritano
  class Plugin
    
    def initialize(stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_path = Etc.getpwuid.dir)
      @stdin = stdin
      @home_dir = home_dir
      @repo_path = repo_path
      @ssh_path = File.join(@home_dir, '.ssh')
    end
    
    def add
      on_add
    end
    
    def remove
      on_remove
    end
    
    def on_add
      raise NotImplementedError
    end
    
    def on_remove
      raise NotImplementedError
    end
    
    def exec(cmd)
      method = cmd[0].split(':').join('_')
      params = cmd[1..-1]
      send(method, params)
    end
    
    def self.name
      self.to_s.downcase.split('::')[-1]
    end
    
    def self.info
      raise NotImplementedError
    end
    
    def self.check_install
      false
    end
    
    def self.list
      @subclass
    end
    
    def self.inherited(subclass)
      @subclass ||= Hash.new
      @subclass[subclass.name] = {klass: subclass, installed: lambda { subclass.check_install }}
    end
    
    def self.add_command(command, parameters = "", &block)
      define_method(command.gsub(':', '_'), &block)
      commands[command] = parameters
    end
    
    def self.commands
      @commands || @commands = Hash.new
    end
    
    def self.bin_name=(name)
      @bin_name = name
    end
    
    def self.bin_name
      @bin_name || "gritano "
    end
    
    def self.help
      msg = "  #{Plugin.bin_name}plugin:exec #{self.name} [command]\n\n"
      msg += "  Examples:\n"
      commands.each do |command, parameters|
        msg += "  #{Plugin.bin_name}plugin:exec #{self.name} #{command} #{parameters}\n"
      end
      msg += "\n  --\n  v#{File.open(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).readlines.join}"
      msg
    end
    
  end
end

require File.join(ROOT_PATH, 'gritano/plugin/ssh')
require File.join(ROOT_PATH, 'gritano/plugin/http')

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gritano-0.10.3 lib/gritano/plugin.rb
gritano-0.10.2 lib/gritano/plugin.rb