Class: Roger::Release
- Inherits:
-
Object
- Object
- Roger::Release
- Defined in:
- lib/roger/release.rb
Defined Under Namespace
Modules: Finalizers, Processors, Scm Classes: Cleaner, Injector
Instance Attribute Summary collapse
-
#cleanups ⇒ Object
readonly
Returns the value of attribute cleanups.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#finalizers ⇒ Object
readonly
Returns the value of attribute finalizers.
-
#injections ⇒ Object
readonly
Returns the value of attribute injections.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Class Method Summary collapse
- .default_finalizers ⇒ Object
- .default_stack ⇒ Object
-
.get_callable(callable, map) ⇒ Object
Makes callable into a object that responds to call.
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.
- #debug(part, msg, &block) ⇒ Object
-
#extract(options = {}) ⇒ Object
deprecated
Deprecated.
Don’t use the extractor anymore, use release.use(:mockup, options) processor
-
#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.
- #get_files(globs, excludes = []) ⇒ Object
-
#initialize(project, config = {}) ⇒ Release
constructor
A new instance of Release.
-
#inject(variables, options) ⇒ Object
Inject variables into files with an optional filter.
-
#log(part, msg, verbose = false, &block) ⇒ Object
Write out a log message.
-
#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 mockup.
-
#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.
-
#warn(part, msg) ⇒ Object
Write out a warning message.
Constructor Details
#initialize(project, config = {}) ⇒ Release
Returns a new instance of Release.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/roger/release.rb', line 48 def initialize(project, config = {}) defaults = { :scm => :git, :source_path => Pathname.new(Dir.pwd) + "html", :target_path => Pathname.new(Dir.pwd) + "releases", :build_path => Pathname.new(Dir.pwd) + "build", :cleanup_build => true } @config = {}.update(defaults).update(config) @project = project @stack = [] @finalizers = [] end |
Instance Attribute Details
#cleanups ⇒ Object (readonly)
Returns the value of attribute cleanups.
8 9 10 |
# File 'lib/roger/release.rb', line 8 def cleanups @cleanups end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/roger/release.rb', line 6 def config @config end |
#finalizers ⇒ Object (readonly)
Returns the value of attribute finalizers.
8 9 10 |
# File 'lib/roger/release.rb', line 8 def finalizers @finalizers end |
#injections ⇒ Object (readonly)
Returns the value of attribute injections.
8 9 10 |
# File 'lib/roger/release.rb', line 8 def injections @injections end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/roger/release.rb', line 6 def project @project end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
8 9 10 |
# File 'lib/roger/release.rb', line 8 def stack @stack end |
Class Method Details
.default_finalizers ⇒ Object
16 17 18 |
# File 'lib/roger/release.rb', line 16 def default_finalizers [[self.get_callable(:dir, Roger::Release::Finalizers.map), {}]] end |
.default_stack ⇒ Object
12 13 14 |
# File 'lib/roger/release.rb', line 12 def default_stack [] end |
.get_callable(callable, map) ⇒ Object
Makes callable into a object that responds to call.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/roger/release.rb', line 24 def get_callable(callable, map) return callable if callable.respond_to?(:call) if callable.kind_of?(Symbol) && map.has_key?(callable) callable = map[callable] end if callable.kind_of?(Class) callable = callable.new end if callable.respond_to?(:call) callable else raise ArgumentError, "Could not resolve #{callable.inspect}. Callable must be an object that responds to #call or a symbol that resolve to such an object or a class with a #call instance method." end 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 =
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/roger/release.rb', line 151 def ( = {}, &block) = { :comment => :js }.update() if block_given? @_banner = yield.to_s elsif !@_banner = [] << "Version : #{self.scm.version}" << "Date : #{self.scm.date.strftime("%Y-%m-%d")}" size = .inject(0){|mem,b| b.size > mem ? b.size : mem } .map!{|b| "= #{b.ljust(size)} =" } div = "=" * .first.size .unshift(div) << div @_banner = .join("\n") end if [:comment] self.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
75 76 77 |
# File 'lib/roger/release.rb', line 75 def build_path Pathname.new(self.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 |
#debug(part, msg, &block) ⇒ Object
225 226 227 |
# File 'lib/roger/release.rb', line 225 def debug(part, msg, &block) self.log(part, msg, true, &block) end |
#extract(options = {}) ⇒ Object
Don’t use the extractor anymore, use release.use(:mockup, options) processor
Extract the mockup, this will happen anyway, and will always happen first This method gives you a way to pass options to the extractor.
184 185 186 187 |
# File 'lib/roger/release.rb', line 184 def extract( = {}) self.warn(self, "Don't use the extractor anymore, use release.use(:mockup, options) and release.use(:url_relativizer, options) processors") @extractor_options = 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, = {}) @finalizers << [self.class.get_callable(finalizer, Roger::Release::Finalizers.map), ] end |
#get_files(globs, excludes = []) ⇒ Object
237 238 239 240 241 242 243 244 |
# File 'lib/roger/release.rb', line 237 def get_files(globs, excludes = []) files = globs.map{|g| Dir.glob(self.build_path + g) }.flatten if excludes.any? files.reject{|c| excludes.detect{|e| e.match(c) } } else files end 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 |
#log(part, msg, verbose = false, &block) ⇒ Object
Write out a log message
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/roger/release.rb', line 211 def log(part, msg, verbose = false, &block) if !verbose || verbose && self.project.[:verbose] self.project.shell.say "\033[37m#{part.class.to_s}\033[0m" + " : " + msg.to_s, nil, true end if block_given? begin self.project.shell.padding = self.project.shell.padding + 1 yield ensure self.project.shell.padding = self.project.shell.padding - 1 end end end |
#run! ⇒ Object
Actually perform the release
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/roger/release.rb', line 190 def run! # Validate paths validate_paths! # Extract mockup copy_source_path_to_build_path! validate_stack! # Run stack run_stack! # Run finalizers run_finalizers! # Cleanup cleanup! if self.config[:cleanup_build] end |
#scm(force = false) ⇒ Object
Get the current SCM object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/roger/release.rb', line 88 def scm(force = false) return @_scm if @_scm && !force case self.config[:scm] when :git @_scm = Release::Scm::Git.new(:path => self.source_path) else raise "Unknown SCM #{[:scm].inspect}" end end |
#source_path ⇒ Object
Accessor for source_path The source path is the root of the mockup
83 84 85 |
# File 'lib/roger/release.rb', line 83 def source_path Pathname.new(self.config[:source_path]) end |
#target_path ⇒ Object
Accessor for target_path The target_path is the path where the finalizers will put the release
67 68 69 |
# File 'lib/roger/release.rb', line 67 def target_path Pathname.new(self.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 |
#warn(part, msg) ⇒ Object
Write out a warning message
230 231 232 |
# File 'lib/roger/release.rb', line 230 def warn(part, msg) self.project.shell.say "\033[37m#{part.class.to_s}\033[0m" + " : " + "\033[31m#{msg.to_s}\033[0m", nil, true end |