Sha256: 32111889b182cb1b16c50b1d38d3deb5d098e097c99881b7b33d09b04547ce5b

Contents?: true

Size: 1.68 KB

Versions: 56

Compression:

Stored size: 1.68 KB

Contents

module MCollective
  module Generators
    class Base
      attr_accessor :meta, :plugin_name, :mod_name
      def initialize(name, description, author, license, version, url, timeout)
        @meta = {:name => name,
                 :description => description,
                 :author => author,
                 :license => license,
                 :version => version,
                 :url => url,
                 :timeout => timeout}
      end

      def create_metadata_string
        ddl_template = File.read(File.join(File.dirname(__FILE__), "templates", "ddl.erb"))
        ERB.new(ddl_template, nil, "-").result(binding)
      end

      def create_plugin_string
        plugin_template = File.read(File.join(File.dirname(__FILE__), "templates", "plugin.erb"))
        ERB.new(plugin_template, nil, "-").result(binding)
      end

      def write_plugins
        begin
          Dir.mkdir @plugin_name
          dirname = File.join(@plugin_name, @mod_name.downcase)
          Dir.mkdir dirname
          puts "Created plugin directory : #{@plugin_name}"

          File.open(File.join(dirname, "#{@plugin_name}.ddl"), "w"){|f| f.puts @ddl}
          puts "Created DDL file : #{File.join(dirname, "#{@plugin_name}.ddl")}"

          File.open(File.join(dirname, "#{@plugin_name}.rb"), "w"){|f| f.puts @plugin}
          puts "Created #{@mod_name} file : #{File.join(dirname, "#{@plugin_name}.rb")}"
        rescue Errno::EEXIST
          raise "cannot generate '#{@plugin_name}' : plugin directory already exists."
        rescue Exception => e
          FileUtils.rm_rf(@plugin_name) if File.directory?(@plugin_name)
          raise "cannot generate plugin - #{e}"
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
mcollective-client-2.8.0 lib/mcollective/generators/base.rb
mcollective-client-2.7.0 lib/mcollective/generators/base.rb
mcollective-client-2.6.1 lib/mcollective/generators/base.rb
mcollective-client-2.6.0 lib/mcollective/generators/base.rb
mcollective-client-2.5.3 lib/mcollective/generators/base.rb
mcollective-client-2.5.2 lib/mcollective/generators/base.rb
mcollective-client-2.5.1 lib/mcollective/generators/base.rb
mcollective-client-2.5.0 lib/mcollective/generators/base.rb
mcollective-client-2.5.0.rc1 lib/mcollective/generators/base.rb
mcollective-client-2.4.1 lib/mcollective/generators/base.rb
mcollective-client-2.4.0 lib/mcollective/generators/base.rb
mcollective-client-2.2.4 lib/mcollective/generators/base.rb
mcollective-client-2.2.3 lib/mcollective/generators/base.rb
mcollective-client-2.2.2 lib/mcollective/generators/base.rb
mcollective-client-2.2.1 lib/mcollective/generators/base.rb
mcollective-client-2.2.0 lib/mcollective/generators/base.rb