Parent

Namespace

Methods

Class/Module Index [+]

Quicksearch

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.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:

Versioning options:

Common packaging options:

Testing options:

Uncommon packaging options:

Security options:

Publishing options:

Documentation options:

Attributes

author[RW]

user-configurable

bin_files[RW]

best left alone

certificate_chain[RW]

user-configurable

changelog[RW]

user-configurable

changelog_patterns[RW]

best left alone

changes[RW]

user-configurable

clean_pattern[RW]

user-configurable

dependencies[RW]

legacy

description[RW]

user-configurable

development_dependencies[RW]

user-configurable

docs_host[RW]

user-configurable

email[RW]

user-configurable

eval[RW]

best left alone

executable_pattern[RW]

user-configurable

extension_pattern[RW]

user-configurable

extensions[RW]

legacy

extra_deps[RW]

legacy

files[RW]

best left alone

gem_bin[RW]

best left alone

gemspec_format[RW]

user-configurable

gemspec_name[RW]

best left alone

has_rdoc[RW]

best left alone

ignore_pattern[RW]

user-configurable

include_gemspec[RW]

best left alone

include_rakefile[RW]

best left alone

install_message[RW]

user-configurable

lib_files[RW]

best left alone

manifest_name[RW]

user-configurable

name[RW]

best left alone

need_gem[RW]

user-configurable

need_tar_gz[RW]

user-configurable

need_tgz[RW]

user-configurable

need_zip[RW]

user-configurable

platform[RW]

user-configurable

private_key[RW]

user-configurable

project[RW]

user-configurable

rakefile_name[RW]

best left alone

rcov_options[RW]

user-configurable

rdoc_files[RW]

legacy

rdoc_options[RW]

best left alone

rdoc_pattern[RW]

user-configurable

rdoc_template[RW]

user-configurable

require_paths[RW]

user-configurable

require_signed[RW]

user-configurable

retain_gemspec[RW]

best left alone

ruby_version[RW]

user-configurable

rubygems_version[RW]

best left alone

runtime_dependencies[RW]

user-configurable

spec[RW]

best left alone

spec_pattern[RW]

user-configurable

summary[RW]

user-configurable

test_files[RW]

best left alone

test_pattern[RW]

user-configurable

url[RW]

user-configurable

use_sudo[RW]

best left alone

version[RW]

user-configurable

Public Class Methods

new(name, _version = nil) click to toggle source
# File lib/echoe.rb, line 164
def initialize(name, _version = nil)
  # Defaults

  self.name = name
  self.project = name.downcase
  self.changelog = "CHANGELOG"
  self.author = ""
  self.email = ""
  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"]
  self.test_pattern = File.exist?("test/test_all.rb") ? "test/test_all.rb" : ['test/**/test_*.rb', 'test/**/*_test.rb']
  self.spec_pattern = "spec/**/*_spec.rb"

  self.ignore_pattern = /^(pkg|doc)|\.svn|CVS|\.bzr|\.DS|\.git/

  self.changelog_patterns = {
      :version => [
          /^\s*v([\d\w\.]+)(\.|\s|$)/,
          /\s*\*\s*([\d\w\.]+)\s*\*\s*$/
        ],
      :changes => [
        /^\s*v([\d\.]+\. .*)/,
        /\*\s*[\d\.]+\s*\*\s*(.*)\*\s*[\d\.]+\s*\*$/
      ]
    }

  self.description = ""
  self.summary = ""
  self.install_message = nil
  self.executable_pattern = /^bin\//
  self.require_paths = nil
  self.has_rdoc = true
  self.use_sudo = !(Platform.windows? or ENV['GEM_HOME'].to_s.include?(ENV['USER'].to_s))
  self.gem_bin = "gem#{Platform.suffix}"
  self.rcov_options = []
  self.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/

  self.gemspec_format = :ruby

  title = (name.downcase == name ? name.capitalize : name)
  self.rdoc_options = ['--line-numbers', '--inline-source', '--title', title]

  readme = Dir['*'].detect { |filename| filename =~ /^readme/ }
  self.rdoc_options += ['--main', readme] if readme

  self.runtime_dependencies = []
  self.development_dependencies = [] # These appear to not work at all
  self.manifest_name = "Manifest"
  self.extension_pattern = ["ext/**/extconf.rb", "ext/extconf.rb"]
  self.private_key = ENV['GEM_PRIVATE_KEY']
  self.require_signed = false
  self.certificate_chain = ENV['GEM_CERTIFICATE_CHAIN'].to_s.split(/\,\s*/).compact

  self.need_gem = true
  self.need_tar_gz = true
  self.need_tgz = false
  self.need_zip = false
  self.platform = $platform

  self.include_rakefile = true
  self.include_gemspec = true
  self.gemspec_name = "#{name}.gemspec"
  self.retain_gemspec = false
  self.rakefile_name = "Rakefile"
  self.rubygems_version = ">= 1.2"

  yield self if block_given?

  self.docs_host ||= "git@github.com:#{self.project}/#{self.project}.github.com"
  if self.docs_host =~ /git@github.com/
    self.url ||= "http://#{self.project}.github.com/#{self.project}/#{(self.name + '/') if project != name}"
  end

  # legacy compatibility
  self.runtime_dependencies = dependencies if dependencies and runtime_dependencies.empty?
  self.runtime_dependencies = extra_deps if extra_deps and runtime_dependencies.empty?
  self.rdoc_pattern = rdoc_files if rdoc_files
  self.extension_pattern = extensions if extensions

  # read manifest
  begin
    self.files = File.readlines(manifest_name).map { |x| x.strip } +
      [(gemspec_name if include_gemspec)] +
      [(rakefile_name if include_rakefile)]
    self.files = files.compact.uniq
  rescue Errno::ENOENT
    unless ARGV.include? "manifest"
      puts "Missing manifest. You can build one with 'rake manifest'."
      exit 1
    else
      self.files = []
    end
  end

  # snag version and changeset
  self.version ||= _version
  unless version
    if File.exist? changelog
      parsed = Array(changelog_patterns[:version]).map do |pattern|
        open(changelog) do |log|
          log.read[pattern, 1]
        end
      end.compact.first
      raise "Could not parse version from #{changelog}" unless parsed
      self.version = parsed.chomp(".").strip
    else
      raise "No #{changelog} found, and no version supplied in Rakefile."
    end
  end

  unless self.changes
    self.changes = if File.exist? changelog
      Array(changelog_patterns[:changes]).map do |pattern|
        open(changelog) do |log|
          log.read[pattern, 1]
        end
      end.compact.first or ""
    else
      ""
    end
  end

  # set some post-defaults
  self.certificate_chain = Array(certificate_chain).map {|file| File.expand_path(file)}
  self.private_key = File.expand_path(private_key) if private_key
  self.description = summary if description.empty?
  self.summary = description if summary.empty?
  self.clean_pattern = apply_pattern(clean_pattern)
  self.extension_pattern = apply_pattern(extension_pattern, files)

  self.ignore_pattern = apply_pattern(ignore_pattern)
  honor_gitignore! if File.exist?(".git")

  self.rdoc_pattern = apply_pattern(rdoc_pattern, files) - [manifest_name]
  self.executable_pattern = apply_pattern(executable_pattern, files)
  self.test_pattern = apply_pattern(test_pattern)
  self.spec_pattern = apply_pattern(spec_pattern)

  define_tasks
end
silence() click to toggle source
# File lib/echoe/extensions.rb, line 14
def self.silence
  if !ENV['VERBOSE']      
    stdout, stderr = $stdout.clone, $stderr.clone
    $stdout.reopen(File.new("#{Dir.tmpdir}/stdout.echoe", 'w'))
    $stderr.reopen(File.new("#{Dir.tmpdir}/stderr.echoe", 'w'))
    begin
      yield
    ensure
      $stdout.reopen(stdout)
      $stderr.reopen(stderr)
    end
  else
    yield
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.