lib/ronin/gen/source_code_generator.rb in ronin-gen-1.0.1 vs lib/ronin/gen/source_code_generator.rb in ronin-gen-1.1.0.rc1
- old
+ new
@@ -20,24 +20,57 @@
require 'ronin/gen/file_generator'
module Ronin
module Gen
#
- # A {FileGenerator} class for creating Ruby files.
+ # A {FileGenerator} class for creating source-code files.
#
class SourceCodeGenerator < FileGenerator
- class_option :editor, :default => ENV['EDITOR']
- class_option :no_edit, :type => :boolean, :default => false
+ parameter :editor, :type => String,
+ :default => ENV['EDITOR']
+ parameter :no_edit, :type => true,
+ :default => false
+
#
- # Generates the source-code file and spawns a text-editor.
+ # Generates the source code file and spawns a text-editor.
#
- def self.generate(options={},arguments=[],&block)
- generator = super(options,arguments,&block)
+ # @since 1.1.0
+ #
+ # @api semipublic
+ #
+ def generate
+ template self.class.template, @path
- if (generator.options.no_edit? && generator.options.editor)
- system(generator.options.editor,generator.path)
+ if (no_edit? && editor?)
+ # spawn the text editor for the newly generated file
+ system(editor,@path)
+ end
+ end
+
+ protected
+
+ #
+ # The template the Source Code Generator will use.
+ #
+ # @param [String] name
+ # The new template name.
+ #
+ # @return [String]
+ # The template the Source Code Generator will use.
+ #
+ # @since 1.1.0
+ #
+ # @api semipublic
+ #
+ def self.template(name=nil)
+ if name
+ @template = name
+ else
+ @template ||= if superclass < SourceCodeGenerator
+ superclass.template
+ end
end
end
end
end