Class: GemHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_ext/project.rb

Class Method Summary collapse

Class Method Details

.gemspecObject



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
82
83
84
85
# File 'lib/rake_ext/project.rb', line 57

def gemspec
  Gem::Specification.new do |s|
    gems, fake_gems = parse_project_gemfile
    gems = gems + fake_gems

    gems.each{|name_version| s.add_dependency *name_version}

    options = project.clone

    options.delete(:name)
    options.delete(:gem) || raise("this project isn't a gem!")
    name = options.delete(:official_name)

    s.name = name
    s.platform = options.delete(:platform) || Gem::Platform::RUBY
    s.has_rdoc = options.delete(:has_rdoc) == nil ? false : true
    s.require_path = options.delete(:lib) || "lib"
    s.files = options.delete(:files) || (
      %w{Rakefile readme.md} +
      Dir.glob("{lib,spec}/**/*") +
      ((options[:dirs] && Array(options.delete(:dirs)).collect{|d| Dir["#{d}/**/*"]}) || [])
    )
    s.bindir = options.delete(:bin) if options.include? :bin

    s.version = options.delete(:version) || GemHelper.next_version(name)

    options.each{|k, v| s.send "#{k}=", v}
  end
end

.next_version(gem_name) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/rake_ext/project.rb', line 29

def next_version gem_name
  %x(gem list --remote #{gem_name}).scan /#{gem_name} \((\d+\.\d+\.\d+)\)/ do |s|
    v = s.first.split('.').collect{|d| d.to_i}
    v[-1] = v[-1] + 1
    return v.join('.')
  end
  return '0.0.1'
end

.parse_project_gemfileObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rake_ext/project.rb', line 38

def parse_project_gemfile
  required_gems, required_fake_gems = [], []
  gem_file = "#{project_dir}/lib/#{project[:name]}/gems.rb"

  if File.exist? gem_file
    # puts "Parsing gemfile #{gem_file}"

    code = File.open(gem_file){|f| f.read}

    stub_class = Class.new
    stub_class.send(:define_method, :gem){|*args| required_gems << args}
    stub_class.send(:define_method, :fake_gem){|*args| required_fake_gems << args}
    stub = stub_class.new
    stub.instance_eval code, __FILE__, __LINE__
  end

  return required_gems, required_fake_gems
end