class Codestrap::Stub::Abstract
@abstract
Template renderer class
Methods (aliased to abstract
) that require overriding
#pre
Pre execution
#execute
Render execution
Methods that may be overridden
#post
Attributes
Path to destination project @!attribute [r] dst @return [String]
Set file object @!attribute [w] file @return [File]
Objects utilized in templates @!attribute [rw] objects @return [Array<Codestrap::Object::Factory>]
Allow overwriting of files @!attribute [rw] overwrite @return [true|false]
Path to template @!attribute [r] src @return [String]
Public Class Methods
List methods aliased Codestrap::Template::Abstract#abstract @return [Array]
# File lib/codestrap/stub/abstract.rb, line 37 def self.abstract_methods instance_methods.group_by { |m| instance_method(m) }.map(&:last).keep_if { |sym| sym.length > 1 }.map { |methods| if methods.include?('abstract'.to_sym) return methods.map { |method| method.to_s }.select { |method| method != 'abstract' } end } [] end
Abstract
class. Raise error on instantiation
# File lib/codestrap/stub/abstract.rb, line 98 def initialize() raise RendererAbstractOnly, 'Abstract Class Requires implementation' end
Public Instance Methods
@abstract Method(s) aliased to this method are considered abstract @raise [RendererRequiredMethod]
Raise an error if a method remains aliased to this method
# File lib/codestrap/stub/abstract.rb, line 106 def abstract raise RendererRequiredMethod, "Method #{__method__.to_s} not implemented" end
Set destination file
@param [String] dst
Path to destination file
# File lib/codestrap/stub/abstract.rb, line 85 def dst=(dst) if !overwrite? and File.exist? dst Codestrap::Core.logger.error(:FILEEXISTS, dst) exit 255 end unless File.exist?(File.dirname(dst)) Codestrap::Core.logger.error(:NOPATH, dst) exit 255 end @dst = dst end
Creates and returns Tempfile to working file
@return [Tempfile]
Path to temporary file
# File lib/codestrap/stub/abstract.rb, line 124 def file @file ||= Tempfile.new('codestrap') end
Check overwrite attribute @return [true|false]
# File lib/codestrap/stub/abstract.rb, line 68 def overwrite? !!@overwite end
Post execution method
# File lib/codestrap/stub/abstract.rb, line 117 def post end
Set source template
@param [String] src
Path to source file
# File lib/codestrap/stub/abstract.rb, line 76 def src=(src) raise Exception, %q[File doesn't exist] unless File.exist?(src) @src = src end
@return [Integer]
Returns 0 on success
# File lib/codestrap/stub/abstract.rb, line 132 def to_disk @file.close tmp = open(@file.path) final = Tempfile.new('codestrap') strip_modeline(tmp, final) tmp.close File.unlink(@file.path) final.close(unlink_now = false) FileUtils.mv final.path, self.dst end
Private Instance Methods
# File lib/codestrap/stub/abstract.rb, line 147 def strip_modeline(src, dst, line_count=10) i = 0 src.each_line do |line| i += 1 dst.write(line) unless line =~ /(?:\b|^)(?:strap|stub):(?:erb|)(?:\b|$)/ and i <= line_count end end