Class: Warbler::Traits::Gemspec

Inherits:
Object
  • Object
show all
Includes:
ExecutableHelper, PathmapHelper, Warbler::Trait
Defined in:
lib/warbler/traits/gemspec.rb

Overview

The Gemspec trait reads a .gemspec file to determine the files, executables, require paths, and dependencies for a project.

Instance Attribute Summary

Attributes included from Warbler::Trait

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExecutableHelper

#executable, #update_archive_add_executable

Methods included from PathmapHelper

#apply_pathmaps

Methods included from Warbler::Trait

#add_init_load_path, #add_main_rb, included, #initialize, #jruby_jars, #update_gem_path

Class Method Details

.detect?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/warbler/traits/gemspec.rb', line 17

def self.detect?
  !Dir['*.gemspec'].empty?
end

Instance Method Details

#after_configureObject


29
30
31
32
33
# File 'lib/warbler/traits/gemspec.rb', line 29

def after_configure
  @spec.require_paths.each do |p|
    add_init_load_path( config.pathmaps.application.inject(p) { |pm,x| pm.pathmap(x) } )
  end
end

#before_configureObject


21
22
23
24
25
26
27
# File 'lib/warbler/traits/gemspec.rb', line 21

def before_configure; require 'yaml'
  @spec_file = Dir['*.gemspec'].first
  @spec = File.open(@spec_file) { |f| Gem::Specification.from_yaml(f) } rescue Gem::Specification.load(@spec_file)
  @spec.runtime_dependencies.each { |g| config.gems << g }
  config.dirs = []
  config.compiled_ruby_files = @spec.files.select { |f| f =~ /\.rb$/ }
end

#default_executableObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/warbler/traits/gemspec.rb', line 55

def default_executable
  if ! @spec.executables.empty?
    exe_script = @spec.executables.first
    exe_path = File.join(@spec.bindir, exe_script) # bin/script
    if File.exists?(exe_path)
      exe_path
    elsif File.exists?("bin/#{exe_script}") # compatibility
      "bin/#{exe_script}" # ... should probably remove this
    else
      raise "no `#{exe_script}` executable script found"
    end
  elsif exe_path = Dir['bin/*'].sort.first
    warn "no executables found in #{@spec_file}, using #{exe_path}"
    exe_path
  elsif exe_path = Dir['exe/*'].sort.first
    warn "no executables found in #{@spec_file}, using #{exe_path}"
    exe_path
  else
    raise "no executable script found"
  end
end

#update_archive(jar) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/warbler/traits/gemspec.rb', line 35

def update_archive(jar)
  @spec.files.each do |f|
    unless File.exist?(f)
      warn "update your gemspec; skipping missing file #{f}"
      next
    end
    file_key = jar.apply_pathmaps(config, f, :application)
    next if jar.files[file_key]
    jar.files[file_key] = f
  end

  config.compiled_ruby_files.each do |f|
    f = f.sub(/\.rb$/, '.class')
    next unless File.exist?(f)
    jar.files[apply_pathmaps(config, f, :application)] = f
  end

  update_archive_add_executable(jar)
end