Class: Tumbler::Updater

Inherits:
Object
  • Object
show all
Includes:
Informer
Defined in:
lib/tumbler/updater.rb

Constant Summary

Constants included from Informer

Informer::Colors

Instance Method Summary collapse

Methods included from Informer

#inform

Constructor Details

#initialize(dir, opts = nil) ⇒ Updater

Returns a new instance of Updater.



10
11
12
13
14
# File 'lib/tumbler/updater.rb', line 10

def initialize(dir, opts = nil)
  @dir = dir
  @name = opts && opts[:name] || File.basename(File.expand_path(dir))
  raise "Couldn't find #{gemspec_path}" unless File.exist?(gemspec_path)
end

Instance Method Details

#changelog_pathObject



100
101
102
# File 'lib/tumbler/updater.rb', line 100

def changelog_path
  File.join(@dir, Manager::Changelog::DEFAULT_FILE)
end

#create_rakefileObject



90
91
92
93
94
# File 'lib/tumbler/updater.rb', line 90

def create_rakefile
  File.open(rakefile_path, 'w') { |f|
    f.puts "require 'tumbler'\nnTumbler.use_rake_tasks"
  }
end

#gemfile_pathObject



108
109
110
# File 'lib/tumbler/updater.rb', line 108

def gemfile_path
  File.join(@dir, 'Gemfile')
end

#gemspec_pathObject



104
105
106
# File 'lib/tumbler/updater.rb', line 104

def gemspec_path
  File.join(@dir, "#{@name}.gemspec")
end

#rakefile_pathObject



82
83
84
# File 'lib/tumbler/updater.rb', line 82

def rakefile_path
  File.join(@dir, 'Rakefile')
end

#tumbler_config_pathObject



86
87
88
# File 'lib/tumbler/updater.rb', line 86

def tumbler_config_path
  File.join(@dir, 'Tumbler')
end

#updateObject



16
17
18
19
20
21
22
23
24
# File 'lib/tumbler/updater.rb', line 16

def update
  inform "Updating gem '#{@name}' at #{@dir}" do
    upgrade_deps
    upgrade_version
    upgrade_changelog
    upgrade_rakefile
    upgrade_tumbler_config
  end
end

#upgrade_changelogObject



64
65
66
67
68
69
70
# File 'lib/tumbler/updater.rb', line 64

def upgrade_changelog
  inform "Examining changelog" do
    unless File.exists?(changelog_path)
      Tumbler::Generate.app(@dir, @name).write_changelog
    end
  end
end

#upgrade_depsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tumbler/updater.rb', line 34

def upgrade_deps
  inform "Examining dependency management" do
    if File.exist?(gemfile_path)
      gemspec = File.read(gemspec_path)
      unless gemspec[/add_bundler_dependencies/] || gemspec[/inject_dependencies/]
        @tainted_gemspec = true
        File.open(gemspec_path, 'a') do |g|
          g << <<-HERE_DOC
  raise # (see below)

  # You probably want to use inject the dependencies using either
  # add_bundler_depenedencies or tumbler.inject_dependencies(spec) (where spec is your Gemspec)
          HERE_DOC
        end
      end
    end
  end
end

#upgrade_rakefileObject



72
73
74
75
76
77
78
79
80
# File 'lib/tumbler/updater.rb', line 72

def upgrade_rakefile
  inform "Examining Rakefile" do
    create_rakefile and return if !File.exist?(rakefile_path)
    rakefile = File.read(rakefile_path)
    if rakefile !~ /Tumbler.use_rake_tasks/
      File.open(rakefile_path, 'a') {|f| f.puts "\n\n# automatically added Tumbler tasks\n\nrequire 'tumbler'\nTumbler.use_rake_tasks"}
    end
  end
end

#upgrade_tumbler_configObject



26
27
28
29
30
31
32
# File 'lib/tumbler/updater.rb', line 26

def upgrade_tumbler_config
  inform "Examining Tumbler config" do
    unless File.exist?(tumbler_config_path)
      Tumbler::Generate.app(@dir, @name).write_tumbler_config
    end
  end
end

#upgrade_versionObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/tumbler/updater.rb', line 53

def upgrade_version
  inform "Examining version tracking" do
    unless File.exists?(version_path)
      # go to rubygems and get it
      gem_data = JSON.parse(Net::HTTP.get(URI.parse("http://rubygems.org/api/v1/gems/#{URI.escape(@name)}.json")))
      version = gem_data['version']
      Tumbler::Generate.app(@dir, @name).write_version(version)
    end
  end
end

#version_pathObject



96
97
98
# File 'lib/tumbler/updater.rb', line 96

def version_path
  File.join(@dir, 'lib', @name, 'version.rb')
end