codestrap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +4 -0
  4. data/.yardopts +3 -0
  5. data/BOILERPLATE.md +151 -0
  6. data/CODESTRAPFILE.md +28 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +13 -0
  9. data/README.md +69 -0
  10. data/Rakefile +51 -0
  11. data/bin/strap +8 -0
  12. data/bin/upstrap +8 -0
  13. data/codestrap.gemspec +37 -0
  14. data/config/projects/codestrap.rb +22 -0
  15. data/config/software/codestrap.rb +20 -0
  16. data/config/software/ruby.rb +247 -0
  17. data/config/software/zlib.rb +86 -0
  18. data/features/client.feature +99 -0
  19. data/features/fixtures/client/home/codestrap/bin/.empty +0 -0
  20. data/features/fixtures/client/home/codestrap/content/bash.erb +3 -0
  21. data/features/fixtures/client/home/codestrap/content/gem/dir/file +0 -0
  22. data/features/fixtures/client/home/codestrap/content/gem/dir/template +3 -0
  23. data/features/fixtures/client/home/codestrap/content/gem/file +1 -0
  24. data/features/fixtures/client/home/codestrap/content/gem/template +3 -0
  25. data/features/fixtures/client/home/codestrap/content/local_remote.erb +1 -0
  26. data/features/fixtures/client/home/codestrap/content/local_remote/dir/file +0 -0
  27. data/features/fixtures/client/home/codestrap/content/local_remote/dir/template +3 -0
  28. data/features/fixtures/client/home/codestrap/content/local_remote/file +1 -0
  29. data/features/fixtures/client/home/codestrap/content/local_remote/template +3 -0
  30. data/features/fixtures/client/home/codestrap/objects/local.json +3 -0
  31. data/features/fixtures/client/output/.empty +0 -0
  32. data/features/fixtures/client/var/lib/codestrap/bin/.empty +0 -0
  33. data/features/fixtures/client/var/lib/codestrap/content/bashremote.erb +3 -0
  34. data/features/fixtures/client/var/lib/codestrap/content/gemremote/dir/file +0 -0
  35. data/features/fixtures/client/var/lib/codestrap/content/gemremote/dir/template +3 -0
  36. data/features/fixtures/client/var/lib/codestrap/content/gemremote/file +0 -0
  37. data/features/fixtures/client/var/lib/codestrap/content/gemremote/template +3 -0
  38. data/features/fixtures/client/var/lib/codestrap/content/remote_local.erb +1 -0
  39. data/features/fixtures/client/var/lib/codestrap/content/remote_local/dir/file +0 -0
  40. data/features/fixtures/client/var/lib/codestrap/content/remote_local/dir/template +3 -0
  41. data/features/fixtures/client/var/lib/codestrap/content/remote_local/file +1 -0
  42. data/features/fixtures/client/var/lib/codestrap/content/remote_local/template +3 -0
  43. data/features/fixtures/client/var/lib/codestrap/content/remote_remote.erb +1 -0
  44. data/features/fixtures/client/var/lib/codestrap/content/remote_remote/dir/file +0 -0
  45. data/features/fixtures/client/var/lib/codestrap/content/remote_remote/dir/template +3 -0
  46. data/features/fixtures/client/var/lib/codestrap/content/remote_remote/file +0 -0
  47. data/features/fixtures/client/var/lib/codestrap/content/remote_remote/template +3 -0
  48. data/features/fixtures/client/var/lib/codestrap/objects/remote.json +3 -0
  49. data/features/fixtures/logging/home/logging/codestrap/bin/stubdirectory/.empty +0 -0
  50. data/features/fixtures/logging/home/logging/codestrap/bin/stubnotlink +0 -0
  51. data/features/fixtures/logging/home/logging/codestrap/content/.empty +0 -0
  52. data/features/fixtures/logging/home/logging/codestrap/objects/.empty +0 -0
  53. data/features/fixtures/server/mixed/var/lib/stub/content/address.erb +3 -0
  54. data/features/fixtures/server/mixed/var/lib/stub/content/cell.erb +3 -0
  55. data/features/fixtures/server/mixed/var/lib/stub/content/email.erb +3 -0
  56. data/features/fixtures/server/mixed/var/lib/stub/content/mobile.erb +3 -0
  57. data/features/fixtures/server/mixed/var/lib/stub/content/name.erb +3 -0
  58. data/features/fixtures/server/mixed/var/lib/stub/content/phone.erb +3 -0
  59. data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/Modulefile +12 -0
  60. data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/README +17 -0
  61. data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/manifests/init.pp +42 -0
  62. data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/spec/spec_helper.rb +18 -0
  63. data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/tests/init.pp +13 -0
  64. data/features/fixtures/server/mixed/var/lib/stub/objects/contact.json +8 -0
  65. data/features/fixtures/server/mixed/var/lib/stub/objects/shadow/contact.json +8 -0
  66. data/features/fixtures/strap/projects/etc/.empty +0 -0
  67. data/features/fixtures/strap/projects/home/user/dir/bin/.empty +0 -0
  68. data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/Modulefile +12 -0
  69. data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/README +17 -0
  70. data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/manifests/:stub:project.name:/subclass.pp +3 -0
  71. data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/manifests/init.pp +42 -0
  72. data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/spec/spec_helper.rb +18 -0
  73. data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/tests/init.pp +13 -0
  74. data/features/fixtures/strap/projects/home/user/dir/objects/contact.json +8 -0
  75. data/features/fixtures/strap/projects/home/user/dir/objects/shadow/contact.json +8 -0
  76. data/features/fixtures/strap/projects/output/.empty +0 -0
  77. data/features/fixtures/stub/contact/etc/.empty +0 -0
  78. data/features/fixtures/stub/contact/home/user/dir/bin/.empty +0 -0
  79. data/features/fixtures/stub/contact/home/user/dir/content/address.erb +3 -0
  80. data/features/fixtures/stub/contact/home/user/dir/content/cell.erb +3 -0
  81. data/features/fixtures/stub/contact/home/user/dir/content/email.erb +3 -0
  82. data/features/fixtures/stub/contact/home/user/dir/content/mobile.erb +3 -0
  83. data/features/fixtures/stub/contact/home/user/dir/content/name.erb +3 -0
  84. data/features/fixtures/stub/contact/home/user/dir/content/phone.erb +3 -0
  85. data/features/fixtures/stub/contact/home/user/dir/objects/contact.json +8 -0
  86. data/features/fixtures/stub/contact/home/user/dir/objects/shadow/contact.json +8 -0
  87. data/features/fixtures/stub/contact/output/.empty +0 -0
  88. data/features/fixtures/stub/date/etc/.empty +0 -0
  89. data/features/fixtures/stub/date/home/user/stub/bin/.empty +0 -0
  90. data/features/fixtures/stub/date/home/user/stub/content/day.erb +3 -0
  91. data/features/fixtures/stub/date/home/user/stub/content/hour.erb +3 -0
  92. data/features/fixtures/stub/date/home/user/stub/content/minute.erb +3 -0
  93. data/features/fixtures/stub/date/home/user/stub/content/month.erb +3 -0
  94. data/features/fixtures/stub/date/home/user/stub/content/second.erb +3 -0
  95. data/features/fixtures/stub/date/home/user/stub/content/year.erb +3 -0
  96. data/features/fixtures/stub/date/home/user/stub/objects/.empty +0 -0
  97. data/features/fixtures/stub/date/output/.empty +0 -0
  98. data/features/fixtures/stub/script/etc/.empty +0 -0
  99. data/features/fixtures/stub/script/home/user/stub/bin/.empty +0 -0
  100. data/features/fixtures/stub/script/home/user/stub/content/credentials.erb +6 -0
  101. data/features/fixtures/stub/script/home/user/stub/objects/credentials.rb +11 -0
  102. data/features/fixtures/stub/script/output/.empty +0 -0
  103. data/features/logging.feature +39 -0
  104. data/features/object_scripts.feature +13 -0
  105. data/features/server.feature +36 -0
  106. data/features/step_definitions/client_steps.rb +99 -0
  107. data/features/step_definitions/logging_steps.rb +65 -0
  108. data/features/step_definitions/object_scripts_steps.rb +26 -0
  109. data/features/step_definitions/server_steps.rb +112 -0
  110. data/features/step_definitions/strap_steps.rb +69 -0
  111. data/features/step_definitions/stub_option_simple_steps.rb +31 -0
  112. data/features/step_definitions/stub_steps.rb +94 -0
  113. data/features/strap.feature +34 -0
  114. data/features/stub.feature +157 -0
  115. data/features/stub_option_simple.feature +14 -0
  116. data/features/stub_packages.feature +15 -0
  117. data/features/support/env.rb +197 -0
  118. data/lib/codestrap.rb +415 -0
  119. data/lib/codestrap/cli.rb +76 -0
  120. data/lib/codestrap/client.rb +179 -0
  121. data/lib/codestrap/config.rb +199 -0
  122. data/lib/codestrap/log.rb +56 -0
  123. data/lib/codestrap/mixin.rb +20 -0
  124. data/lib/codestrap/namespace.rb +19 -0
  125. data/lib/codestrap/object/abstract.rb +33 -0
  126. data/lib/codestrap/object/factory.rb +86 -0
  127. data/lib/codestrap/object/standard/datetime.rb +24 -0
  128. data/lib/codestrap/object/standard/files.rb +40 -0
  129. data/lib/codestrap/object/standard/project.rb +33 -0
  130. data/lib/codestrap/object/standard/rest.rb +30 -0
  131. data/lib/codestrap/patch.rb +122 -0
  132. data/lib/codestrap/server/rest.rb +177 -0
  133. data/lib/codestrap/server/version.rb +5 -0
  134. data/lib/codestrap/strap/abstract.rb +135 -0
  135. data/lib/codestrap/strap/factory.rb +85 -0
  136. data/lib/codestrap/strap/standard.rb +95 -0
  137. data/lib/codestrap/stub/abstract.rb +156 -0
  138. data/lib/codestrap/stub/factory.rb +87 -0
  139. data/lib/codestrap/stub/standard.rb +23 -0
  140. data/lib/codestrap/version.rb +3 -0
  141. data/omnibus.rb +53 -0
  142. data/package-scripts/codestrap/postinst +25 -0
  143. data/package-scripts/codestrap/postrm +17 -0
  144. data/package-scripts/codestrap/preinst +7 -0
  145. data/package-scripts/codestrap/prerm +15 -0
  146. data/resources/codestrap/pkg/background.png +0 -0
  147. data/resources/codestrap/pkg/distribution.xml.erb +22 -0
  148. data/resources/codestrap/pkg/license.html.erb +202 -0
  149. data/resources/codestrap/pkg/welcome.html.erb +7 -0
  150. metadata +466 -0
@@ -0,0 +1,5 @@
1
+ module Codestrap
2
+ module Server
3
+ VERSION = '1.0'
4
+ end
5
+ end
@@ -0,0 +1,135 @@
1
+ require 'codestrap/mixin'
2
+ require 'tmpdir'
3
+
4
+ module Codestrap
5
+ module Strap
6
+ # @abstract
7
+ #
8
+ # Boilerplate renderer class
9
+ #
10
+ # Methods (aliased to #abstract) that require overriding
11
+ #
12
+ # #pre
13
+ #
14
+ # Pre execution
15
+ #
16
+ # #execute
17
+ #
18
+ # Render execution
19
+ #
20
+ # Methods that may be overridden
21
+ #
22
+ # #post
23
+ #
24
+ class Abstract
25
+ include Codestrap::Mixin::Exceptions::Template
26
+
27
+ # Objects utilized in templates
28
+ # @!attribute [rw] objects
29
+ # @return [Codestrap::Object::Factory]
30
+ attr_accessor :objects
31
+
32
+ # List of files to ignore
33
+ # @!attribute [rw] ignore
34
+ # @return [Array]
35
+ attr_accessor :ignore
36
+
37
+ # List methods aliased to Codestrap::Template::Abstract#abstract
38
+ # @return [Array]
39
+ def self.abstract_methods
40
+ instance_methods.group_by { |m| instance_method(m) }.map(&:last).keep_if { |sym| sym.length > 1 }.map { |methods|
41
+ if methods.include?('abstract'.to_sym)
42
+ return methods.map { |method| method.to_s }.select { |method| method != 'abstract' }
43
+ end
44
+ }
45
+ []
46
+ end
47
+
48
+ # Path to project
49
+ # @!attribute [r] src
50
+ # @return [String]
51
+ attr_reader :src
52
+
53
+ # Path to destination file
54
+ # @!attribute [r] dst
55
+ # @return [String]
56
+ attr_reader :dst
57
+
58
+ # Allow overwrite of files
59
+ # @!attribute [rw] overwrite
60
+ # @return [true|false]
61
+ attr_accessor :overwrite
62
+
63
+ # Check overwrite attribute
64
+ # @return [true|false]
65
+ def overwrite?
66
+ !!@overwrite
67
+ end
68
+
69
+ # Set source project
70
+ #
71
+ # @param [String] src
72
+ # Path to source directory
73
+ def src=(src)
74
+ raise Exception, %q[File doesn't exist] unless File.exist?(src)
75
+ @src = src
76
+ end
77
+
78
+ # Set destination project
79
+ #
80
+ # @param [String] dst
81
+ # Path to destination directory
82
+ def dst=(dst)
83
+ if !overwrite? and File.exist? dst
84
+ Codestrap::Core.logger.error(:FILEEXISTS, dst)
85
+ exit 255
86
+ end
87
+ unless File.exist?(File.dirname(dst))
88
+ Codestrap::Core.logger.error(:NOPATH, dst)
89
+ exit 255
90
+ end
91
+ @dst = dst
92
+ end
93
+
94
+ # Abstract class. Raise error on instantiation
95
+ def initialize
96
+ raise RendererAbstractOnly, 'Abstract Class Requires implementation'
97
+ end
98
+
99
+ # @abstract
100
+ # Method(s) aliased to this method are considered abstract
101
+ # @raise [RendererRequiredMethod]
102
+ # Raise an error if a method remains aliased to this method
103
+ def abstract
104
+ raise RendererRequiredMethod, "Method #{__method__.to_s} not implemented"
105
+ end
106
+
107
+ # Pre execution abstract method
108
+ alias :pre :abstract
109
+
110
+ # Execution abstract method
111
+ alias :execute :abstract
112
+
113
+ # Post execution method
114
+ def post
115
+ end
116
+
117
+ # Creates and returns path to working directory
118
+ #
119
+ # @return [Dir]
120
+ def working_dir
121
+ @working_dir ||= Dir.new(Dir.mktmpdir('strap'))
122
+ end
123
+
124
+ # Moves #working_dir contents to #dst
125
+ #
126
+ # @return [Integer]
127
+ # Returns 0 on success
128
+ def to_disk
129
+ FileUtils.mv self.working_dir.path, self.dst
130
+ end
131
+
132
+ alias_method :file, :working_dir
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,85 @@
1
+ require 'codestrap/mixin'
2
+
3
+ module Codestrap
4
+ module Strap
5
+ # Factory for instantiating classes from the Codestrap::Strap namespace
6
+ class Factory
7
+ include Codestrap::Mixin::Exceptions::Factory
8
+
9
+ attr_reader :klass
10
+
11
+ # Factory constructor for Codestrap::Template::* Classes
12
+ #
13
+ # @param [Class, Symbol, String] nklass
14
+ # @return [Codestrap::Stub::Factory]
15
+ def initialize(nklass)
16
+ self.klass = nklass
17
+ enforce_methods
18
+ ensure_required
19
+ end
20
+
21
+ # Constructor for Codestrap::Strap::* Classes
22
+ #
23
+ # @param [Array] args
24
+ # Arguments to pass to constructor of child object
25
+ # @return [Object]
26
+ # Return the object as specified Factory#klass.new(args)
27
+ def construct(*args)
28
+ self.klass.new(args)
29
+ end
30
+
31
+ # Dynamic Class creation.
32
+ # Looks for Classes in Codestrap::Strap::NKLASS
33
+ #
34
+ # @param [String|Symbol] nklass
35
+ # Look for Codestrap::Template::nklass
36
+ # @raise [FactoryArgumentError]
37
+ # Raised if nklass is not type String or type Symbol
38
+ # @return [Codestrap::Stub::KLASS]
39
+ # Return class Codestrap::Template::KLASS
40
+ def to_class nklass
41
+ case
42
+ when nklass.is_a?(Symbol)
43
+ klass = nklass.to_s
44
+ when nklass.is_a?(String)
45
+ klass = nklass
46
+ else
47
+ raise ArgumentError, %Q(Could not find Class Codestrap::Strap::#{nklass.to_s})
48
+ end
49
+ @klass = ['Codestrap', 'Strap', klass].reduce(Module, :const_get)
50
+ @klass
51
+ end
52
+
53
+ alias :klass= :to_class
54
+
55
+ # Ensure self.klass has the following methods
56
+ #
57
+ # klass.pre
58
+ # klass.execute
59
+ #
60
+ # Inherited from Codestrap::Template::Factory
61
+ # klass.file
62
+ # klass.finalize
63
+ #
64
+ # @raise [FactoryMethodEnforcement]
65
+ # Raised if a enforced method doesn't exist in the child
66
+ # @return [TrueClass, FalseClass]
67
+ def enforce_methods
68
+ [:pre, :execute, :overwrite, :overwrite=, :working_dir, :to_disk].each do |method|
69
+ next if @klass.method_defined? method
70
+ raise FactoryException, "Error missing method #{@klass.to_s}##{method}"
71
+ end
72
+ end
73
+
74
+ # Ensures any methods aliased to abstract_method are overridden
75
+ # @raise [FactoryAbstractMethod]
76
+ # Raised if a abstract method (A method aliased to abstract_method), is not created in the child
77
+ def ensure_required
78
+ if @klass.abstract_methods.length > 0
79
+ methods = @klass.abstract_methods.map{ |method| "#{@klass.to_s}##{method}" }
80
+ raise FactoryException, "Abstract Method(s) #{methods.join(', ')} not overridden"
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,95 @@
1
+ require 'erb'
2
+ require 'find'
3
+ require 'fileutils'
4
+ require 'ostruct'
5
+ require 'codestrap/namespace'
6
+ require 'codestrap/patch'
7
+ require 'codestrap/strap/abstract'
8
+ require 'ptools'
9
+ require 'tmpdir'
10
+
11
+ module Codestrap
12
+ module Strap
13
+ # Standard project renderer
14
+ #
15
+ class Standard < Abstract
16
+
17
+ def initialize(*args)
18
+ self.working_dir
19
+ end
20
+
21
+ def pre
22
+ @compiled ||= []
23
+
24
+ # Take ignored array from Codestrap.config
25
+ ignore_hash = {}
26
+ Array(self.ignore).each do |ignore|
27
+ ignore_hash[ignore] = true
28
+ end
29
+ Find.find(self.src) do |src|
30
+ # Ignore files
31
+ if ignore_hash.has_key? File.basename(src)
32
+ Find.prune
33
+ end
34
+
35
+ proj_path = String(src.gsub(/^#{Regexp.escape(self.src)}/, ''))
36
+
37
+ # Destination path substitutions
38
+ proj_path =~ /:(?:stub|strap):(.+?):/
39
+ object = $1
40
+ replacement = proj_path.gsub(/:(?:stub|strap):.+?:/, "<%= #{object} %>")
41
+ if proj_path != replacement
42
+ # Regex replacement
43
+ ns = Codestrap::Namespace.new(self.objects.objects)
44
+ erb = ERB.new(replacement)
45
+ proj_path = erb.result(ns.get_binding)
46
+ end
47
+
48
+ dst = File.join(self.working_dir, proj_path)
49
+
50
+ # Directories
51
+ if File.directory? src
52
+ @compiled.push({file: proj_path, src: src, dst: dst, type: :dir})
53
+ next
54
+ end
55
+
56
+ # Files
57
+ file = Codestrap::Patch::File.new src
58
+ if file.stat.file?
59
+ # Read modeline
60
+ if not File.binary?(src) and file.has_mode_line?
61
+ # Templates
62
+ @compiled.push({file: proj_path, src: src, dst: dst, type: file.template})
63
+ else
64
+ # Files
65
+ @compiled.push({file: proj_path, src: src, dst: dst, type: :regular})
66
+ end
67
+ next
68
+ end
69
+ end
70
+ end
71
+
72
+ def execute
73
+ @compiled.each do |obj|
74
+ case obj[:type]
75
+ when :dir
76
+ FileUtils.mkpath obj[:dst]
77
+ when :regular
78
+ FileUtils.install obj[:src], obj[:dst]
79
+ when :erb
80
+ renderer = Codestrap::Stub::Factory.new('Standard').construct
81
+ renderer.objects = self.objects
82
+ renderer.src = obj[:src]
83
+ renderer.dst = obj[:dst]
84
+ renderer.pre
85
+ renderer.execute
86
+ renderer.post
87
+ renderer.to_disk
88
+ else
89
+ raise Exception, "Unknown type: #{obj[:type].to_s}"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,156 @@
1
+ require 'singleton'
2
+ require 'ostruct'
3
+ require 'erb'
4
+ require 'codestrap/mixin'
5
+ require 'tempfile'
6
+
7
+ module Codestrap
8
+ module Stub
9
+ # @abstract
10
+ #
11
+ # Template renderer class
12
+ #
13
+ # Methods (aliased to #abstract) that require overriding
14
+ #
15
+ # #pre
16
+ #
17
+ # Pre execution
18
+ #
19
+ # #execute
20
+ #
21
+ # Render execution
22
+ #
23
+ # Methods that may be overridden
24
+ #
25
+ # #post
26
+ #
27
+ class Abstract
28
+ include Codestrap::Mixin::Exceptions::Template
29
+
30
+ # Objects utilized in templates
31
+ # @!attribute [rw] objects
32
+ # @return [Array<Codestrap::Object::Factory>]
33
+ attr_accessor :objects
34
+
35
+ # List methods aliased Codestrap::Template::Abstract#abstract
36
+ # @return [Array]
37
+ def self.abstract_methods
38
+ instance_methods.group_by { |m| instance_method(m) }.map(&:last).keep_if { |sym| sym.length > 1 }.map { |methods|
39
+ if methods.include?('abstract'.to_sym)
40
+ return methods.map { |method| method.to_s }.select { |method| method != 'abstract' }
41
+ end
42
+ }
43
+ []
44
+ end
45
+
46
+ # Set file object
47
+ # @!attribute [w] file
48
+ # @return [File]
49
+ attr_writer :file
50
+
51
+ # Path to template
52
+ # @!attribute [r] src
53
+ # @return [String]
54
+ attr_reader :src
55
+
56
+ # Path to destination project
57
+ # @!attribute [r] dst
58
+ # @return [String]
59
+ attr_reader :dst
60
+
61
+ # Allow overwriting of files
62
+ # @!attribute [rw] overwrite
63
+ # @return [true|false]
64
+ attr_accessor :overwrite
65
+
66
+ # Check overwrite attribute
67
+ # @return [true|false]
68
+ def overwrite?
69
+ !!@overwite
70
+ end
71
+
72
+ # Set source template
73
+ #
74
+ # @param [String] src
75
+ # Path to source file
76
+ def src=(src)
77
+ raise Exception, %q[File doesn't exist] unless File.exist?(src)
78
+ @src = src
79
+ end
80
+
81
+ # Set destination file
82
+ #
83
+ # @param [String] dst
84
+ # Path to destination file
85
+ def dst=(dst)
86
+ if !overwrite? and File.exist? dst
87
+ Codestrap::Core.logger.error(:FILEEXISTS, dst)
88
+ exit 255
89
+ end
90
+ unless File.exist?(File.dirname(dst))
91
+ Codestrap::Core.logger.error(:NOPATH, dst)
92
+ exit 255
93
+ end
94
+ @dst = dst
95
+ end
96
+
97
+ # Abstract class. Raise error on instantiation
98
+ def initialize()
99
+ raise RendererAbstractOnly, 'Abstract Class Requires implementation'
100
+ end
101
+
102
+ # @abstract
103
+ # Method(s) aliased to this method are considered abstract
104
+ # @raise [RendererRequiredMethod]
105
+ # Raise an error if a method remains aliased to this method
106
+ def abstract
107
+ raise RendererRequiredMethod, "Method #{__method__.to_s} not implemented"
108
+ end
109
+
110
+ # Pre execution method
111
+ alias :pre :abstract
112
+
113
+ # Execution method
114
+ alias :execute :abstract
115
+
116
+ # Post execution method
117
+ def post
118
+ end
119
+
120
+ # Creates and returns Tempfile to working file
121
+ #
122
+ # @return [Tempfile]
123
+ # Path to temporary file
124
+ def file
125
+ @file ||= Tempfile.new('codestrap')
126
+ end
127
+
128
+ # Moves #file contents to #dst
129
+ #
130
+ # @return [Integer]
131
+ # Returns 0 on success
132
+ def to_disk
133
+ @file.close
134
+ tmp = open(@file.path)
135
+ final = Tempfile.new('codestrap')
136
+ strip_modeline(tmp, final)
137
+
138
+ tmp.close
139
+ File.unlink(@file.path)
140
+ final.close(unlink_now = false)
141
+
142
+ FileUtils.mv final.path, self.dst
143
+ end
144
+
145
+ private
146
+
147
+ def strip_modeline(src, dst, line_count=10)
148
+ i = 0
149
+ src.each_line do |line|
150
+ i += 1
151
+ dst.write(line) unless line =~ /(?:\b|^)(?:strap|stub):(?:erb|)(?:\b|$)/ and i <= line_count
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end