Module: Rubinjam
- Defined in:
- lib/rubinjam.rb,
lib/rubinjam/version.rb,
lib/rubinjam/internal.rb
Defined Under Namespace
Modules: BaseAutoloadFix, ModuleAutoloadFix
Constant Summary
collapse
'#!/usr/bin/env ruby'.freeze
- VERSION =
"0.5.1"
- ROOT =
File.expand_path("../", __FILE__) << "/rubinjam/"
Class Method Summary
collapse
Class Method Details
.file_from_nesting(mod, const) ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/rubinjam/internal.rb', line 14
def file_from_nesting(mod, const)
if file = mod.rubinjam_autload[const]
return [mod, file]
end
nesting(mod.name)[1..-1].detect do |mod|
file = mod.rubinjam_autload[const]
break [mod, file] if file
end
end
|
.nesting(name) ⇒ Object
this does not reflect the actual Module.nesting of the caller, but it should be close enough
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rubinjam/internal.rb', line 27
def nesting(name)
nesting = []
namespace = name.split("::")
namespace.inject(Object) do |base, n|
klass = base.const_get(n)
nesting << klass
klass
end
nesting.reverse
end
|
.normalize_file(file) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/rubinjam/internal.rb', line 5
def normalize_file(file)
return file unless file.start_with?("/")
if file.start_with?(ROOT)
file.sub(ROOT, "")
else
file.split('/lib/').last
end
end
|
.pack(dir) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/rubinjam.rb', line 9
def pack(dir)
Dir.chdir(dir) do
binaries = Dir["bin/*"]
raise "No binary found in ./bin" if binaries.size == 0
raise "Can only pack exactly 1 binary, found #{binaries.join(",")} in ./bin" unless binaries.size == 1
content = environment + File.read(binaries.first)
[File.basename(binaries.first), content]
end
end
|
.pack_gem(gem, version = nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/rubinjam.rb', line 19
def pack_gem(gem, version=nil)
require "shellwords"
require "rubygems/package"
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
command = "gem fetch #{Shellwords.escape(gem)}"
command << " -v" << version if version
sh(command)
gem_ball = Dir["*.gem"].first
spec = Gem::Package.new(gem_ball).spec.to_ruby
sh("gem unpack #{gem_ball}")
Dir.chdir(gem_ball.sub(".gem", "")) do
File.open("#{gem}.gemspec", "w") { |f| f.write spec }
Rubinjam.pack(Dir.pwd)
end
end
end
end
|