Class: Warbler::Traits::Bundler
- Inherits:
-
Object
- Object
- Warbler::Traits::Bundler
show all
- Includes:
- Warbler::Trait
- Defined in:
- lib/warbler/traits/bundler.rb
Overview
The Bundler trait uses Bundler to determine gem dependencies to be added to the project.
Instance Attribute Summary
#config
Class Method Summary
collapse
Instance Method Summary
collapse
#add_init_load_path, #add_main_rb, included, #initialize, #update_gem_path
Class Method Details
.detect? ⇒ Boolean
15
16
17
|
# File 'lib/warbler/traits/bundler.rb', line 15
def self.detect?
File.exist?(ENV['BUNDLE_GEMFILE'] || "Gemfile")
end
|
.requires?(trait) ⇒ Boolean
19
20
21
|
# File 'lib/warbler/traits/bundler.rb', line 19
def self.requires?(trait)
trait == Traits::War || trait == Traits::Jar
end
|
Instance Method Details
#add_bundler_files(jar) ⇒ Object
Add Bundler Gemfiles and git repositories to the archive.
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/warbler/traits/bundler.rb', line 72
def add_bundler_files(jar)
pwd = Pathname.new(Dir.pwd)
gemfile = config.bundler[:gemfile].relative_path_from(pwd).to_s
lockfile = config.bundler[:lockfile].relative_path_from(pwd).to_s
jar.files[jar.apply_pathmaps(config, gemfile, :application)] = config.bundler[:gemfile].to_s
if File.exist?(lockfile)
jar.files[jar.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!(%r{^/+}, '')
config.pathmaps.git = [pathmap]
config.bundler[:git_specs].each do |spec|
full_gem_path = Pathname.new(spec.full_gem_path)
FileList["#{full_gem_path.to_s}/**/*"].each do |src|
f = Pathname.new(src).relative_path_from(full_gem_path).to_s
next if config.gem_excludes && config.gem_excludes.any? {|rx| f =~ rx }
jar.files[jar.apply_pathmaps(config, File.join(full_gem_path.basename, f), :git)] = src
end
end
end
end
|
#add_bundler_gems ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/warbler/traits/bundler.rb', line 32
def add_bundler_gems
config.gems.clear
config.gem_dependencies = false config.bundler = {}
ENV['BUNDLE_WITHOUT'] ||= config.bundle_without.join(':')
require 'bundler'
::Bundler.setup.requested_specs.each do |spec|
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.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[:lockfile] = ::Bundler.default_lockfile
config.bundler[:frozen] = ::Bundler.settings[:frozen]
config.excludes += [::Bundler.settings[:path]] if ::Bundler.settings[:path]
config.init_contents << "#{config.warbler_templates}/bundler.erb"
end
|
28
29
30
|
# File 'lib/warbler/traits/bundler.rb', line 28
def after_configure
add_bundler_gems if config.bundler
end
|
23
24
25
26
|
# File 'lib/warbler/traits/bundler.rb', line 23
def before_configure
config.bundler = true
config.bundle_without = ["development", "test"]
end
|
#update_archive(jar) ⇒ Object
67
68
69
|
# File 'lib/warbler/traits/bundler.rb', line 67
def update_archive(jar)
add_bundler_files(jar) if config.bundler
end
|