Class: RailsUpgrade::Upgraders::GemfileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-upgrade/upgraders/gems.rb

Instance Method Summary collapse

Constructor Details

#initializeGemfileGenerator

Returns a new instance of GemfileGenerator.



26
27
28
# File 'lib/rails-upgrade/upgraders/gems.rb', line 26

def initialize
  @gems = []
end

Instance Method Details

#gem(name, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/rails-upgrade/upgraders/gems.rb', line 30

def gem(name, options={})
  data = {}
  
  # Add new keys from old keys
  data[:require_as] = options[:lib] if options[:lib]
  data[:source] = options[:source] if options[:source]
  
  version = options[:version]
  @gems << [name, version, data]
end

#generate_upgraded_codeObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rails-upgrade/upgraders/gems.rb', line 53

def generate_upgraded_code    
  code = @gems.map do |name, version, data|
    version_string = (version ? ", '#{version}'" : "")
    source = data.delete(:source)
    # omg hax.  again.
    data_string = ""
    
    unless data.empty?
      data_string = data.inspect.match(/^\{(.*)\}$/)[1]
    end
    
    if source
      "source '#{source}'\ngem '#{name}'#{version_string}#{data_string}"
    else
      "gem '#{name}'#{version_string}, #{data_string}"
    end
  end.join("\n")
end

#outputObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rails-upgrade/upgraders/gems.rb', line 41

def output
  preamble = <<STR
# Edit this Gemfile to bundle your application's dependencies.
# This preamble is the current preamble for Rails 3 apps; edit as needed.
directory "/path/to/rails", :glob => "{*/,}*.gemspec"
git "git://github.com/rails/arel.git"
git "git://github.com/rails/rack.git"
gem "rails", "3.0.pre"
STR
  preamble + "\n" + generate_upgraded_code
end