Parent

Warbler::Traits::Bundler

The Bundler trait uses Bundler to determine gem dependencies to be added to the project.

Public Class Methods

detect?() click to toggle source
# File lib/warbler/traits/bundler.rb, line 16
def self.detect?
  File.exist?(ENV['BUNDLE_GEMFILE'] || "Gemfile")
end
requires?(trait) click to toggle source
# File lib/warbler/traits/bundler.rb, line 20
def self.requires?(trait)
  trait == Traits::War || trait == Traits::Jar
end

Public Instance Methods

add_bundler_files(jar) click to toggle source

Add Bundler Gemfiles and git repositories to the archive.

# File lib/warbler/traits/bundler.rb, line 78
def add_bundler_files(jar)
  gemfile  = relative_from_pwd(config.bundler[:gemfile])
  lockfile = relative_from_pwd(config.bundler[:lockfile])
  jar.files[apply_pathmaps(config, gemfile, :application)] = config.bundler[:gemfile].to_s
  if File.exist?(lockfile)
    jar.files[apply_pathmaps(config, lockfile, :application)] = config.bundler[:lockfile].to_s
  end
  if config.bundler[:git_specs]
    pathmap = "#{config.relative_gem_path}/bundler/gems/%p"
    pathmap.sub!(%{^/+}, '')
    config.pathmaps.git = [pathmap]
    config.bundler[:git_specs].each do |spec|
      full_gem_path = Pathname.new(spec.full_gem_path)

      gem_relative_path = full_gem_path.relative_path_from(::Bundler.install_path)
      filenames = []
      gem_relative_path.each_filename { |f| filenames << f }

      exclude_gems = true
      unless filenames.empty?
        full_gem_path = Pathname.new(::Bundler.install_path) + filenames.first
        exclude_gems = false
      end

      if spec.groups.include?(:warbler_excluded)
        pattern = "#{full_gem_path.to_s}/**/#{spec.name}.gemspec" # #42: gemspec only to avert Bundler error
      else
        pattern = "#{full_gem_path.to_s}/**/*"
      end

      FileList[pattern].each do |src|
        f = Pathname.new(src).relative_path_from(full_gem_path).to_s
        next if exclude_gems && config.gem_excludes && config.gem_excludes.any? {|rx| f =~ rx }
        jar.files[apply_pathmaps(config, File.join(full_gem_path.basename, f), :git)] = src
      end
    end
  end
end
add_bundler_gems() click to toggle source
# File lib/warbler/traits/bundler.rb, line 33
def add_bundler_gems
  require 'bundler'
  config.gems.clear
  config.gem_dependencies = false # Bundler takes care of these
  config.bundler = {}

  bundler_specs.each do |spec|
    # Bundler HAX -- fixup bad #loaded_from attribute in fake
    # bundler gemspec from bundler/source.rb
    if spec.name == "bundler"
      full_gem_path = Pathname.new(spec.full_gem_path)
      tries = 2
      (full_gem_path = full_gem_path.dirname; tries -= 1) while tries > 0 && !full_gem_path.join('bundler.gemspec').exist?
      spec.loaded_from = full_gem_path.join('bundler.gemspec').to_s
      # RubyGems 1.8.x: @full_gem_path is cached, so we have to set it
      def spec.full_gem_path=(p); @full_gem_path = p; end
      spec.full_gem_path = full_gem_path.to_s
    end

    case spec.source
    when ::Bundler::Source::Git
      config.bundler[:git_specs] ||= []
      config.bundler[:git_specs] << spec
    when ::Bundler::Source::Path
      $stderr.puts("warning: Bundler `path' components are not currently supported.",
                   "The `#{spec.full_name}' component was not bundled.",
                   "Your application may fail to boot!")
    else
      config.gems << spec
    end
  end
  config.bundler[:gemfile]  = ::Bundler.default_gemfile
  config.bundler[:gemfile_path] = apply_pathmaps(config, relative_from_pwd(::Bundler.default_gemfile), :application)
  config.bundler[:lockfile] = ::Bundler.default_lockfile
  config.bundler[:frozen] = ::Bundler.settings[:frozen]
  path = ::Bundler.settings[:path]
  config.excludes += [path, "#{path}/**/*"] if path
  config.init_contents << "#{config.warbler_templates}/bundler.erb"
end
after_configure() click to toggle source
# File lib/warbler/traits/bundler.rb, line 29
def after_configure
  add_bundler_gems if config.bundler
end
before_configure() click to toggle source
# File lib/warbler/traits/bundler.rb, line 24
def before_configure
  config.bundler = true
  config.bundle_without = ["development", "test"]
end
relative_from_pwd(path) click to toggle source
# File lib/warbler/traits/bundler.rb, line 117
def relative_from_pwd(path)
  if path.relative?
    path
  else
    path.relative_path_from(Pathname.new(Dir.pwd)).to_s
  end
end
update_archive(jar) click to toggle source
# File lib/warbler/traits/bundler.rb, line 73
def update_archive(jar)
  add_bundler_files(jar) if config.bundler
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.