Class: Warbler::Traits::Bundler
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
to_spec
#apply_pathmaps
#add_init_load_path, #add_main_rb, included, #initialize, #jruby_jars, #update_gem_path
Class Method Details
.detect? ⇒ Boolean
17
18
19
|
# File 'lib/warbler/traits/bundler.rb', line 17
def self.detect?
File.exist?(ENV['BUNDLE_GEMFILE'] || "Gemfile")
end
|
.requirements ⇒ Object
21
22
23
|
# File 'lib/warbler/traits/bundler.rb', line 21
def self.requirements
[ Traits::War, Traits::Jar ]
end
|
Instance Method Details
#add_bundler_files(jar) ⇒ Object
Add Bundler Gemfiles and git repositories to the archive.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/warbler/traits/bundler.rb', line 88
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!(%r{^/+}, '')
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" 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 ⇒ Object
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/warbler/traits/bundler.rb', line 34
def add_bundler_gems; require 'bundler'
config.gem_dependencies = false config.bundler = {} if config.bundler == true
bundler_specs.each do |spec|
spec = to_spec(spec)
if spec.name == 'bundler'
full_gem_path = Pathname.new(spec.full_gem_path)
while ! full_gem_path.join('bundler.gemspec').exist?
full_gem_path = full_gem_path.dirname
if full_gem_path.to_s =~ /^[\.\/]$/
$stderr.puts("warning: Unable to detect bundler spec under '#{spec.full_gem_path}'' and is sub-dirs")
exit
end
end
spec.loaded_from = full_gem_path.join('bundler.gemspec').to_s
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
unless bundler_source_is_warbled_gem_itself?(spec.source)
$stderr.puts("warning: Bundler `path' components are not currently supported.",
"The `#{spec.full_name}' component was not bundled.",
"Your application may fail to boot!")
end
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
|
30
31
32
|
# File 'lib/warbler/traits/bundler.rb', line 30
def after_configure
add_bundler_gems if config.bundler
end
|
25
26
27
28
|
# File 'lib/warbler/traits/bundler.rb', line 25
def before_configure
config.bundler ||= true
config.bundle_without = ['development', 'test', 'assets']
end
|
#relative_from_pwd(path) ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/warbler/traits/bundler.rb', line 127
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) ⇒ Object
83
84
85
|
# File 'lib/warbler/traits/bundler.rb', line 83
def update_archive(jar)
add_bundler_files(jar) if config.bundler
end
|