Class: Codestrap::Stub::Abstract Abstract

Inherits:
Object
  • Object
show all
Includes:
Mixin::Exceptions::Template
Defined in:
lib/codestrap/stub/abstract.rb

Overview

This class is abstract.

Template renderer class

Methods (aliased to #abstract) that require overriding

#pre

Pre execution

#execute

Render execution

Methods that may be overridden

#post

Direct Known Subclasses

Standard

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbstract

Abstract class. Raise error on instantiation



98
99
100
# File 'lib/codestrap/stub/abstract.rb', line 98

def initialize()
  raise RendererAbstractOnly, 'Abstract Class Requires implementation'
end

Instance Attribute Details

#dstString

Path to destination project

Returns:

  • (String)


59
60
61
# File 'lib/codestrap/stub/abstract.rb', line 59

def dst
  @dst
end

#fileTempfile

Creates and returns Tempfile to working file

Returns:

  • (Tempfile)

    Path to temporary file



124
125
126
# File 'lib/codestrap/stub/abstract.rb', line 124

def file
  @file ||= Tempfile.new('codestrap')
end

#objectsArray<Codestrap::Object::Factory>

Objects utilized in templates

Returns:



33
34
35
# File 'lib/codestrap/stub/abstract.rb', line 33

def objects
  @objects
end

#overwritetrue|false

Allow overwriting of files

Returns:

  • (true|false)


64
65
66
# File 'lib/codestrap/stub/abstract.rb', line 64

def overwrite
  @overwrite
end

#srcString

Path to template

Returns:

  • (String)


54
55
56
# File 'lib/codestrap/stub/abstract.rb', line 54

def src
  @src
end

Class Method Details

.abstract_methodsArray

List methods aliased Codestrap::Template::Abstract#abstract

Returns:

  • (Array)


37
38
39
40
41
42
43
44
# 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

Instance Method Details

#abstractObject Also known as: pre, execute

This method is abstract.

Method(s) aliased to this method are considered abstract

Raises:



106
107
108
# File 'lib/codestrap/stub/abstract.rb', line 106

def abstract
  raise RendererRequiredMethod, "Method #{__method__.to_s} not implemented"
end

#overwrite?true|false

Check overwrite attribute

Returns:

  • (true|false)


68
69
70
# File 'lib/codestrap/stub/abstract.rb', line 68

def overwrite?
  !!@overwite
end

#postObject

Post execution method



117
118
# File 'lib/codestrap/stub/abstract.rb', line 117

def post
end

#to_diskInteger

Moves #file contents to #dst

Returns:

  • (Integer)

    Returns 0 on success



132
133
134
135
136
137
138
139
140
141
142
143
# 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