Class: Echoe

Echoe includes some optional accessors for more advanced gem configuration.

For example, a simple Rakefile might look like this:

  require 'echoe'

  Echoe.new("uncapitalizer") do |p|
    p.author = "Evan Weaver"
    p.summary = "A library that uncapitalizes strings."
    p.url = "http://www.uncapitalizer.com"
    p.docs_host = "uncapitalizer.com:~/www/files/doc/"
    p.runtime_dependencies = ["string_tools >=1.4.0"]
  end

See below for the full list.

Signing gems

Echoe supports signing gems. First, create yourself a public and private key:

  gem cert --build you@yourmail.com

Move them somewhere secret, and add the following environment variables in your .bash_profile or similar:

  export GEM_PRIVATE_KEY='/secret/path/to/gem-private_key.pem'
  export GEM_CERTIFICATE_CHAIN='/secret/path/to/gem-public_cert.pem'

Make sure your environment is up-to-date:

  source ~/.bash_profile

Upload your public_cert.pem file to your website or Rubyforge project, and tell your users to add that certificate to their system via:

  gem cert --add /path/to/public_cert.pem

Finally, package and release your project as normal. Now users can install your gem via:

  sudo gem install gemname -P HighSecurity

Note that you can also set the key and certificate locations in the Rakefile itself. Finally, you can add p.require_signed = true to your Rakefile so that you don‘t accidentally release an unsigned gem if your key is missing.

Metadependencies

Echoe does not force packages to depend on Echoe itself. Instead, it generates a gemspec from your Rakefile and includes that. Downstream repackagers can use the gemspec as-is to build new versions of your gem even without Echoe.

Cross-packaging

Echoe supports platform Rake targets to allow you to cross-package your gems. Just write the spec assuming RUBY_PLATFORM will be what you need it to be for each architecture, and then invoke Rake with the platform name when you‘re cross-packaging.

For example, on JRuby, rake package will build a generic -ruby type gem. But if you want to include a Java-specific extension, you can do one of two things. You can package from within JRuby by checking if RUBY_PLATFORM =~ /java/ and setting p.platform = jruby, or you can run rake java package, which will set RUBY_PLATFORM and p.platform for you.

This way you can run rake java package, rake aix install, or whatever task you need and Echoe will behave just like you‘re packaging from within the target platform.

Test environment setup and teardown

For some applications, you may need to setup and teardown environment state for the entire test suite. This is especially common for integration tests that may need to spawn an external daemon. To support this, you can add a file tests/setup.rb and it will be silently executed before the entire suite runs. Add a similar file tests/teardown.rb in your app to be executed at the end of the entire run.

Note; these files will only get executed if you run the tests via rake. Also, you can set the environment variable VERBOSE=1 to not hide the setup/teardown output.

Accessor options

Descriptive options:

  • author - Your name.
  • email - Your email address.
  • description - A more detailed description of the library.
  • summary - A shorter description of the library.
  • url - A url for the library.
  • install_message - A message to display after the gem is installed.

Versioning options:

  • version - A string for the version number. Parsed from CHANGELOG otherwise.
  • changes - A string describing the most recent changes. Parsed from CHANGELOG otherwise.

Common packaging options:

  • runtime_dependencies - An array of runtime dependencies for this gem. For example, [‘mongrel’, ‘activesupport >= 2.0.2’].
  • development_dependencies - An array of development dependencies for this gem. For example, [‘rake >=0.7.1’].
  • extension_pattern - A filename array, glob array, or regex for extension files that need to be run at install time. Defaults to "ext/**/extconf.rb".

Testing options:

  • clean_pattern - A filename array, glob array, or regex for files that should be removed when rake clean is run.
  • test_pattern - A filename array, glob array, or regex for test runners. Overridden by "test/test_all.rb", if it exists.
  • spec_pattern - A filename array, glob array, or regex for test runners.
  • rcov_options - Any extra flags to pass to RCov when coverage reports are run.

Uncommon packaging options:

  • platform - What platform this gem is for.
  • manifest_name - The name of the manifest file. Defaults to Manifest.
  • need_gem - Whether to generate a gem package. Defaults to true.
  • need_tar_gz - Whether to generate a .tar.gz package. Defaults to true.
  • need_tgz - Whether to generate a .tgz package. Defaults to false.
  • need_zip - Whether to generate a .zip package. Defaults to false.
  • include_rakefile - Include the Rakefile directly within the package. Defaults to true.
  • include_gemspec - Include the generated gemspec file within the package. Defaults to true.
  • ruby_version - Version string for which Ruby to require (for example, ’>= 1.8.4‘.
  • eval - Accepts a proc to be evaluated in the context of the Gem::Specification object. This allows you to set more unusual gemspec options.
  • ignore_pattern - A filename array, glob array, or regex for pathnames that should be ignored when building the manifest.
  • require_paths - Non-standard requirement paths to add to the gem definition.
  • executable_pattern - A filename array, glob array, or regex for files that should be installed as wrapped executables.

Security options:

  • private_key - The path to your gem private key. Defaults to ENV[‘GEM_PRIVATE_KEY’], if available. This accessor is not published in the resulting gemspec.
  • certificate_chain - An array representing your certificate authorization chain. If no one else has signed your certificate, just set it to your own cert. Defaults to ENV[‘GEM_CERTIFICATE_CHAIN’], if available. This accessor is not published in the resulting gemspec.
  • require_signed - Force Echoe to refuse to package your gem if it‘s not properly signed. Default false.

Publishing options:

  • project - The name of the Rubyforge project. Defaults to the name of the gem.
  • docs_host - A host and filesystem path to publish the documentation to. Defaults to the Rubyforge project.

Documentation options:

  • rdoc_pattern - A filename array, glob array, or regex for filenames that should be passed to RDoc.
  • rdoc_template - A path to an RDoc template. Defaults to the generic template.

Child modules and classes

Module Echoe::Platform

Attributes

NameRead/write?
author RW
bin_files RW
certificate_chain RW
changelog RW
changelog_patterns RW
changes RW
clean_pattern RW
dependencies RW
description RW
development_dependencies RW
docs_host RW
email RW
eval RW
executable_pattern RW
extension_pattern RW
extensions RW
extra_deps RW
files RW
gem_bin RW
gemspec_format RW
gemspec_name RW
has_rdoc RW
ignore_pattern RW
include_gemspec RW
include_rakefile RW
install_message RW
lib_files RW
manifest_name RW
name RW
need_gem RW
need_tar_gz RW
need_tgz RW
need_zip RW
platform RW
private_key RW
project RW
rakefile_name RW
rcov_options RW
rdoc_files RW
rdoc_options RW
rdoc_pattern RW
rdoc_template RW
require_paths RW
require_signed RW
retain_gemspec RW
ruby_version RW
rubyforge_name RW
rubygems_version RW
runtime_dependencies RW
spec RW
spec_pattern RW
summary RW
test_files RW
test_pattern RW
url RW
use_sudo RW
version RW

Public Class Methods


new (name, _version = nil) {|self if block_given?| ...}

     # File lib/echoe.rb, line 161
161:   def initialize(name, _version = nil)
162:     # Defaults
163: 
164:     self.name = name
165:     self.project = name.downcase
166:     self.changelog = "CHANGELOG"
167:     self.url = ""
168:     self.author = ""
169:     self.email = ""
170:     self.clean_pattern = ["pkg", "doc", 'build/*', '**/coverage', '**/*.o', '**/*.so', '**/*.a', '**/*.log', "{ext,lib}/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/Makefile", "{ext,lib}/**/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/**/Makefile", "pkg", "*.gem", ".config"]
171:     self.test_pattern = File.exist?("test/test_all.rb") ? "test/test_all.rb" : ['test/**/test_*.rb', 'test/**/*_test.rb']
172:     self.spec_pattern = "spec/**/*_spec.rb"
173:     
174:     self.ignore_pattern = /^(pkg|doc)|\.svn|CVS|\.bzr|\.DS|\.git/
175:     
176:     self.changelog_patterns = {
177:         :version => [
178:             /^\s*v([\d\.]+)(\.|\s|$)/,
179:             /\s*\*\s*([\d\.]+)\s*\*\s*$/
180:           ],
181:         :changes => [
182:           /^\s*v([\d\.]+\. .*)/,
183:           /\*\s*[\d\.]+\s*\*\s*(.*)\*\s*[\d\.]+\s*\*$/m
184:         ]
185:       }
186: 
187:     self.description = ""
188:     self.summary = ""
189:     self.install_message = nil
190:     self.executable_pattern = /^bin\//
191:     self.require_paths = nil
192:     self.has_rdoc = true
193:     self.use_sudo = !Platform.windows?
194:     self.gem_bin = "gem#{Platform.suffix}"
195:     self.rcov_options = []
196:     self.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
197: 
198:     self.gemspec_format = :ruby
199: 
200:     title = (name.downcase == name ? name.capitalize : name)
201:     self.rdoc_options = ['--line-numbers', '--inline-source', '--title', title]
202: 
203:     readme = Dir['*'].detect { |filename| filename =~ /^readme/i }
204:     self.rdoc_options += ['--main', readme] if readme
205: 
206:     self.runtime_dependencies = []
207:     self.development_dependencies = [] # These appear to not work at all
208:     self.manifest_name = "Manifest"
209:     self.extension_pattern = ["ext/**/extconf.rb", "ext/extconf.rb"]
210:     self.private_key = ENV['GEM_PRIVATE_KEY']
211:     self.require_signed = false
212:     self.certificate_chain = ENV['GEM_CERTIFICATE_CHAIN'].to_s.split(/\,\s*/).compact
213: 
214:     self.need_gem = true
215:     self.need_tar_gz = true
216:     self.need_tgz = false
217:     self.need_zip = false
218:     self.platform = $platform
219: 
220:     self.include_rakefile = true
221:     self.include_gemspec = true
222:     self.gemspec_name = "#{name}.gemspec"
223:     self.retain_gemspec = false
224:     self.rakefile_name = "Rakefile"
225:     self.rubygems_version = ">= 1.2"
226: 
227:     yield self if block_given?
228: 
229:     # legacy compatibility
230:     self.runtime_dependencies = dependencies if dependencies and runtime_dependencies.empty?
231:     self.runtime_dependencies = extra_deps if extra_deps and runtime_dependencies.empty?
232:     self.project = rubyforge_name if rubyforge_name
233:     self.rdoc_pattern = rdoc_files if rdoc_files
234:     self.extension_pattern = extensions if extensions
235: 
236:     # read manifest
237:     begin
238:       self.files = File.readlines(manifest_name).map { |x| x.strip } +
239:         [(gemspec_name if include_gemspec)] +
240:         [(rakefile_name if include_rakefile)]
241:       self.files = files.compact.uniq
242:     rescue Errno::ENOENT
243:       unless ARGV.include? "manifest"
244:         puts "Missing manifest. You can build one with 'rake manifest'."
245:         exit 1
246:       else
247:         self.files = []
248:       end
249:     end
250: 
251:     # snag version and changeset
252:     self.version ||= _version
253:     unless version
254:       if File.exist? changelog
255:         parsed = Array(changelog_patterns[:version]).map do |pattern|
256:           open(changelog) do |log|
257:             log.read[pattern, 1]
258:           end
259:         end.compact.first
260:         raise "Could not parse version from #{changelog}" unless parsed
261:         self.version = parsed.chomp(".").strip
262:       else
263:         raise "No #{changelog} found, and no version supplied in Rakefile."
264:       end
265:     end
266: 
267:     unless self.changes
268:       self.changes = if File.exist? changelog
269:         Array(changelog_patterns[:changes]).map do |pattern|
270:           open(changelog) do |log|
271:             log.read[pattern, 1]
272:           end
273:         end.compact.first or ""
274:       else
275:         ""
276:       end
277:     end
278: 
279:     # set some post-defaults
280:     self.certificate_chain = Array(certificate_chain).map {|file| File.expand_path(file)}
281:     self.private_key = File.expand_path(private_key) if private_key
282:     self.description = summary if description.empty?
283:     self.summary = description if summary.empty?
284:     self.clean_pattern = apply_pattern(clean_pattern)
285:     self.extension_pattern = apply_pattern(extension_pattern, files)
286:     
287:     self.ignore_pattern = apply_pattern(ignore_pattern)
288:     honor_gitignore! if File.exist?(".git")
289:     
290:     self.rdoc_pattern = apply_pattern(rdoc_pattern, files) - [manifest_name]
291:     self.executable_pattern = apply_pattern(executable_pattern, files)
292:     self.test_pattern = apply_pattern(test_pattern)
293:     self.spec_pattern = apply_pattern(spec_pattern)
294: 
295:     define_tasks
296:   end

silence () {|| ...}

    # File lib/echoe/extensions.rb, line 14
14:   def self.silence
15:     if !ENV['VERBOSE']      
16:       stdout, stderr = $stdout.clone, $stderr.clone
17:       $stdout.reopen(File.new('/tmp/stdout.echoe', 'w'))
18:       $stderr.reopen(File.new('/tmp/stderr.echoe', 'w'))
19:       begin
20:         yield
21:       ensure
22:         $stdout.reopen(stdout)
23:         $stderr.reopen(stderr)
24:       end
25:     else
26:       yield
27:     end
28:   end