Module: Rubinjam

Defined in:
lib/rubinjam.rb,
lib/rubinjam/tasks.rb,
lib/rubinjam/version.rb,
lib/rubinjam/internal.rb

Defined Under Namespace

Modules: BaseAutoloadFix, ModuleAutoloadFix, Tasks

Constant Summary collapse

HEADER =
'#!/usr/bin/env ruby'.freeze
VERSION =
"0.7.0"
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

pack a directory



19
20
21
22
23
24
25
# File 'lib/rubinjam.rb', line 19

def pack(dir)
  Dir.chdir(dir) do
    binary = binary_path
    content = environment + File.read(binary)
    return [File.basename(binary), content]
  end
end

.pack_gem(gem, version = nil) ⇒ Object

pack a gem



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubinjam.rb', line 28

def pack_gem(gem, version=nil)
  require "shellwords"
  require "rubygems/package"

  Dir.mktmpdir do |dir|
    Dir.chdir(dir) do
      # fetch
      command = "gem fetch #{Shellwords.escape(gem)}"
      command << " -v" << Shellwords.escape(version) if version
      sh(command)

      # load spec
      gem_ball = Dir["*.gem"].first
      spec = Gem::Package.new(gem_ball).spec.to_ruby
      sh("gem unpack #{Shellwords.escape(gem_ball)}")

      # bundle
      Dir.chdir(gem_ball.sub(".gem", "")) do
        write_file "#{gem}.gemspec", spec
        Rubinjam.pack(Dir.pwd)
      end
    end
  end
end

.write(dir) ⇒ Object

pack and write a binary given a directory



10
11
12
13
14
15
16
# File 'lib/rubinjam.rb', line 10

def write(dir)
  name, content = pack(Dir.pwd)
  write_file name, content
  `chmod +x #{name}`
  raise "Unable to add execution bit" unless $?.success?
  name
end