Class: Codestrap::Stub::Abstract Abstract
- Inherits:
-
Object
- Object
- Codestrap::Stub::Abstract
- Includes:
- Mixin::Exceptions::Template
- Defined in:
- lib/codestrap/stub/abstract.rb
Overview
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
Instance Attribute Summary collapse
-
#dst ⇒ String
Path to destination project.
-
#file ⇒ Tempfile
Creates and returns Tempfile to working file.
-
#objects ⇒ Array<Codestrap::Object::Factory>
Objects utilized in templates.
-
#overwrite ⇒ true|false
Allow overwriting of files.
-
#src ⇒ String
Path to template.
Class Method Summary collapse
-
.abstract_methods ⇒ Array
List methods aliased Codestrap::Template::Abstract#abstract.
Instance Method Summary collapse
-
#abstract ⇒ Object
(also: #pre, #execute)
abstract
Method(s) aliased to this method are considered abstract.
-
#initialize ⇒ Abstract
constructor
Abstract class.
-
#overwrite? ⇒ true|false
Check overwrite attribute.
-
#post ⇒ Object
Post execution method.
-
#to_disk ⇒ Integer
Moves #file contents to #dst.
Constructor Details
#initialize ⇒ Abstract
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
#dst ⇒ String
Path to destination project
59 60 61 |
# File 'lib/codestrap/stub/abstract.rb', line 59 def dst @dst end |
#file ⇒ Tempfile
Creates and returns Tempfile to working file
124 125 126 |
# File 'lib/codestrap/stub/abstract.rb', line 124 def file @file ||= Tempfile.new('codestrap') end |
#objects ⇒ Array<Codestrap::Object::Factory>
Objects utilized in templates
33 34 35 |
# File 'lib/codestrap/stub/abstract.rb', line 33 def objects @objects end |
#overwrite ⇒ true|false
Allow overwriting of files
64 65 66 |
# File 'lib/codestrap/stub/abstract.rb', line 64 def overwrite @overwrite end |
#src ⇒ String
Path to template
54 55 56 |
# File 'lib/codestrap/stub/abstract.rb', line 54 def src @src end |
Class Method Details
.abstract_methods ⇒ Array
List methods aliased Codestrap::Template::Abstract#abstract
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
#abstract ⇒ Object Also known as: pre, execute
Method(s) aliased to this method are considered abstract
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
68 69 70 |
# File 'lib/codestrap/stub/abstract.rb', line 68 def overwrite? !!@overwite end |
#post ⇒ Object
Post execution method
117 118 |
# File 'lib/codestrap/stub/abstract.rb', line 117 def post end |
#to_disk ⇒ Integer
Moves #file contents to #dst
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 |