Class: Roger::Release
- Inherits:
-
Object
- Object
- Roger::Release
- Extended by:
- Helpers::GetCallable
- Includes:
- Helpers::GetFiles, Helpers::Logging
- Defined in:
- lib/roger/release.rb,
lib/roger/release/scm.rb,
lib/roger/release/scm/git.rb,
lib/roger/release/scm/fixed.rb
Overview
The release runner
Direct Known Subclasses
Defined Under Namespace
Modules: Finalizers, Processors, Scm Classes: Cleaner, Injector
Constant Summary
Constants included from Helpers::GetFiles
Helpers::GetFiles::GLOB_OPTIONS
Constants included from Helpers::Logging
Helpers::Logging::GRAY, Helpers::Logging::RED
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
-
#banner(options = {}, &_block) ⇒ Object
Generates a banner if a block is given, or returns the currently set banner.
-
#build_path ⇒ Object
Accessor for build_path The build_path is a temporary directory where the release will be built.
-
#cleanup(pattern) ⇒ Object
Files to clean up in the build directory just before finalization happens.
- #comment(string, options = {}) ⇒ Object
-
#finalize(finalizer, options = {}) ⇒ Object
Write out the whole release into a directory, zip file or anything you can imagine #finalize can be called multiple times, it just will run all of them.
-
#initialize(project, config = {}) ⇒ Release
constructor
A new instance of Release.
-
#inject(variables, options) ⇒ Object
Inject variables into files with an optional filter.
-
#run! ⇒ Object
Actually perform the release.
-
#scm(force = false) ⇒ Object
Get the current SCM object.
-
#source_path ⇒ Object
Accessor for source_path The source path is the root of the project.
-
#target_path ⇒ Object
Accessor for target_path The target_path is the path where the finalizers will put the release.
-
#use(processor, options = {}) ⇒ Object
Use a certain pre-processor.
Methods included from Helpers::GetCallable
Methods included from Helpers::GetFiles
Methods included from Helpers::Logging
Constructor Details
#initialize(project, config = {}) ⇒ Release
Returns a new instance of Release.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/roger/release.rb', line 30 def initialize(project, config = {}) real_project_path = project.path.realpath defaults = { scm: :git, source_path: project.html_path.realpath, target_path: real_project_path + "releases", build_path: real_project_path + "build", cp: lambda do |source, dest| if RUBY_PLATFORM.match("mswin") || RUBY_PLATFORM.match("mingw") unless system(["echo d | xcopy", "/E", "/Y", source.to_s.gsub("/", "\\"), dest.to_s.gsub("/", "\\")].join(" ")) raise "Could not copy build directory using xcopy" end else unless system(Shellwords.join(["cp", "-LR", "#{source}/", dest.to_s])) raise "Could not copy build directory using cp" end end end, blank: false, cleanup_build: true } @config = {}.update(defaults).update(config) @project = project @stack = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/roger/release.rb', line 14 def config @config end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
14 15 16 |
# File 'lib/roger/release.rb', line 14 def project @project end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
16 17 18 |
# File 'lib/roger/release.rb', line 16 def stack @stack end |
Instance Method Details
#banner(options = {}, &_block) ⇒ Object
Generates a banner if a block is given, or returns the currently set banner. It automatically takes care of adding comment marks around the banner.
The default banner looks like this:
=======================
Version : v1.0.0 =
Date : 2012-06-20 =
=======================
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/roger/release.rb', line 152 def ( = {}, &_block) = { comment: :js }.update() if block_given? @_banner = yield.to_s elsif !@_banner @_banner = .join("\n") end if [:comment] comment(@_banner, style: [:comment]) else @_banner end end |
#build_path ⇒ Object
Accessor for build_path The build_path is a temporary directory where the release will be built
71 72 73 |
# File 'lib/roger/release.rb', line 71 def build_path Pathname.new(config[:build_path]) end |
#cleanup(pattern) ⇒ Object
Files to clean up in the build directory just before finalization happens
135 136 137 |
# File 'lib/roger/release.rb', line 135 def cleanup(pattern) @stack << Cleaner.new(pattern) end |
#comment(string, options = {}) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/roger/release.rb', line 196 def comment(string, = {}) = { style: :css, per_line: true }.update() commenters = { html: proc { |s| "<!-- #{s} -->" }, css: proc { |s| "/* #{s} */" }, js: proc { |s| "/* #{s} */" } } commenter = commenters[[:style]] || commenters[:js] if [:per_line] string = string.split(/\r?\n/) string.map { |s| commenter.call(s) }.join("\n") else commenter.call(string) end end |
#finalize(finalizer, options = {}) ⇒ Object
Write out the whole release into a directory, zip file or anything you can imagine #finalize can be called multiple times, it just will run all of them.
The default finalizer is :dir
125 126 127 |
# File 'lib/roger/release.rb', line 125 def finalize(finalizer, = {}) @stack << [self.class.get_callable(finalizer, Roger::Release::Finalizers.map), ] end |
#inject(variables, options) ⇒ Object
Inject variables into files with an optional filter
104 105 106 |
# File 'lib/roger/release.rb', line 104 def inject(variables, ) @stack << Injector.new(variables, ) end |
#run! ⇒ Object
Actually perform the release
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/roger/release.rb', line 171 def run! project.mode = :release # Validate paths validate_paths! # Extract mockup copy_source_path_to_build_path! validate_stack! # Run stack run_stack! # Cleanup cleanup! if config[:cleanup_build] ensure project.mode = nil end |
#scm(force = false) ⇒ Object
Get the current SCM object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/roger/release.rb', line 84 def scm(force = false) return @_scm if @_scm && !force case config[:scm] when :git @_scm = Release::Scm::Git.new(path: source_path) when :fixed @_scm = Release::Scm::Fixed.new else raise "Unknown SCM #{[:scm].inspect}" end end |
#source_path ⇒ Object
Accessor for source_path The source path is the root of the project
79 80 81 |
# File 'lib/roger/release.rb', line 79 def source_path Pathname.new(config[:source_path]) end |
#target_path ⇒ Object
Accessor for target_path The target_path is the path where the finalizers will put the release
63 64 65 |
# File 'lib/roger/release.rb', line 63 def target_path Pathname.new(config[:target_path]) end |
#use(processor, options = {}) ⇒ Object
Use a certain pre-processor
112 113 114 |
# File 'lib/roger/release.rb', line 112 def use(processor, = {}) @stack << [self.class.get_callable(processor, Roger::Release::Processors.map), ] end |