Class: Roger::Release

Inherits:
Object
  • Object
show all
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,
lib/roger/release/processors.rb

Overview

The release runner

Direct Known Subclasses

Testing::MockRelease

Defined Under Namespace

Modules: Finalizers, Processors, Scm Classes: Cleaner, Injector

Constant Summary

Constants included from Helpers::Logging

Helpers::Logging::GRAY, Helpers::Logging::RED

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::GetCallable

get_callable

Methods included from Helpers::GetFiles

#get_files

Methods included from Helpers::Logging

#debug, #log, #warn

Constructor Details

#initialize(project, config = {}) ⇒ Release

Returns a new instance of Release.

Parameters:

  • config (Hash) (defaults to: {})

    a customizable set of options

Options Hash (config):

  • :scm (:git, :fixed)

    The SCM to use (default = :git)

  • :target_path (String, Pathname)

    The path/directory to put the release into

  • :build_path (String, Pathname)

    Temporary path used to build the release

  • :cleanup_build (Boolean)

    Wether or not to remove the build_path after we’re done (default = true)

  • :cp (Array, String, nil)

    CP command to use; Array will be escaped with Shellwords. Pass nil to get native Ruby CP. (default = [“cp”, “-RL”])

  • :blank (Boolean)

    Keeps the release clean, don’t automatically add any processors or finalizers (default = false)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/roger/release.rb', line 38

def initialize(project, config = {})
  real_project_path = project.path.realpath
  defaults = {
    scm: :git,
    source_path: real_project_path + "html",
    target_path: real_project_path + "releases",
    build_path: real_project_path + "build",
    cp: ["cp", "-RL"],
    blank: false,
    cleanup_build: true
  }

  @config = {}.update(defaults).update(config)

  @project = project
  @stack = []
  @finalizers = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/roger/release.rb', line 13

def config
  @config
end

#finalizersObject (readonly)

Returns the value of attribute finalizers.



15
16
17
# File 'lib/roger/release.rb', line 15

def finalizers
  @finalizers
end

#projectObject (readonly)

Returns the value of attribute project.



13
14
15
# File 'lib/roger/release.rb', line 13

def project
  @project
end

#stackObject (readonly)

Returns the value of attribute stack.



15
16
17
# File 'lib/roger/release.rb', line 15

def stack
  @stack
end

Class Method Details

.default_finalizersObject



24
25
26
# File 'lib/roger/release.rb', line 24

def default_finalizers
  [[get_callable(:dir, Roger::Release::Finalizers.map), {}]]
end

.default_stackObject



20
21
22
# File 'lib/roger/release.rb', line 20

def default_stack
  []
end

Instance Method Details

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 =

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :comment (:css, :js, :html, false)

    Wether or not to comment the output and in what style. (default=js)



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/roger/release.rb', line 150

def banner(options = {}, &_block)
  options = {
    comment: :js
  }.update(options)

  if block_given?
    @_banner = yield.to_s
  elsif !@_banner
    @_banner = default_banner.join("\n")
  end

  if options[:comment]
    comment(@_banner, style: options[:comment])
  else
    @_banner
  end
end

#build_pathObject

Accessor for build_path The build_path is a temporary directory where the release will be built

Returns:

  • Pathname the build_path



69
70
71
# File 'lib/roger/release.rb', line 69

def build_path
  Pathname.new(config[:build_path])
end

#cleanup(pattern) ⇒ Object

Files to clean up in the build directory just before finalization happens

Parameters:

  • Pattern (String)

    to glob within build directory



133
134
135
# File 'lib/roger/release.rb', line 133

def cleanup(pattern)
  @stack << Cleaner.new(pattern)
end

#comment(string, options = {}) ⇒ Object

Parameters:

  • string (String)

    The string to comment

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :style (:html, :css, :js)

    The comment style to use (default=:js, which is the same as :css)

  • :per_line (Boolean)

    Comment per line or make one block? (default=true)



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/roger/release.rb', line 197

def comment(string, options = {})
  options = {
    style: :css,
    per_line: true
  }.update(options)

  commenters = {
    html: proc { |s| "<!-- #{s} -->" },
    css: proc { |s| "/* #{s} */" },
    js: proc { |s| "/* #{s} */" }
  }

  commenter = commenters[options[:style]] || commenters[:js]

  if options[: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

Parameters:

  • Finalizer (Symbol, Proc)

    to use



123
124
125
# File 'lib/roger/release.rb', line 123

def finalize(finalizer, options = {})
  @finalizers << [self.class.get_callable(finalizer, Roger::Release::Finalizers.map), options]
end

#inject(variables, options) ⇒ Object

Inject variables into files with an optional filter



102
103
104
# File 'lib/roger/release.rb', line 102

def inject(variables, options)
  @stack << Injector.new(variables, options)
end

#run!Object

Actually perform the release



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/roger/release.rb', line 169

def run!
  project.mode = :release

  # 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 config[:cleanup_build]
ensure
  project.mode = nil
end

#scm(force = false) ⇒ Object

Get the current SCM object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/roger/release.rb', line 82

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
    fail "Unknown SCM #{options[:scm].inspect}"
  end
end

#source_pathObject

Accessor for source_path The source path is the root of the project

Returns:

  • Pathname the source_path



77
78
79
# File 'lib/roger/release.rb', line 77

def source_path
  Pathname.new(config[:source_path])
end

#target_pathObject

Accessor for target_path The target_path is the path where the finalizers will put the release

Returns:

  • Pathname the target_path



61
62
63
# File 'lib/roger/release.rb', line 61

def target_path
  Pathname.new(config[:target_path])
end

#use(processor, options = {}) ⇒ Object

Use a certain pre-processor



110
111
112
# File 'lib/roger/release.rb', line 110

def use(processor, options = {})
  @stack << [self.class.get_callable(processor, Roger::Release::Processors.map), options]
end