Class: FluentPluginGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/command/plugin_generator.rb

Defined Under Namespace

Classes: ApacheLicense, NoLicense

Constant Summary collapse

SUPPORTED_TYPES =
["input", "output", "filter", "parser", "formatter", "storage"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ FluentPluginGenerator

Returns a new instance of FluentPluginGenerator.



32
33
34
35
36
37
38
# File 'lib/fluent/command/plugin_generator.rb', line 32

def initialize(argv = ARGV)
  @argv = argv
  @parser = prepare_parser

  @license_name = "Apache-2.0"
  @overwrite_all = false
end

Instance Attribute Details

#license_nameObject (readonly)

Returns the value of attribute license_name.



28
29
30
# File 'lib/fluent/command/plugin_generator.rb', line 28

def license_name
  @license_name
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/fluent/command/plugin_generator.rb', line 27

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



27
28
29
# File 'lib/fluent/command/plugin_generator.rb', line 27

def type
  @type
end

Instance Method Details

#callObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fluent/command/plugin_generator.rb', line 40

def call
  parse_options!
  FileUtils.mkdir_p(gem_name)
  Dir.chdir(gem_name) do
    copy_license
    template_directory.find do |path|
      next if path.directory?
      dest_dir = path.dirname.sub(/\A#{Regexp.quote(template_directory.to_s)}\/?/, "")
      dest_file = dest_filename(path)
      if path.extname == ".erb"
        if path.fnmatch?("*/plugin/*")
          next unless path.basename.fnmatch?("*#{type}*")
        end
        template(path, dest_dir + dest_file)
      else
        file(path, dest_dir + dest_file)
      end
    end
    pid = spawn("git", "init", ".")
    Process.wait(pid)
  end
end