Class: Jeweler
- Inherits:
-
Object
- Object
- Jeweler
- Defined in:
- lib/jeweler.rb,
lib/jeweler/tasks.rb,
lib/jeweler/errors.rb,
lib/jeweler/gemspec.rb,
lib/jeweler/version.rb,
lib/jeweler/generator.rb
Overview
A Jeweler helps you craft the perfect Rubygem. Give him a gemspec, and he takes care of the rest.
Defined Under Namespace
Classes: FileInTheWay, GemSpecHelper, GemspecError, Generator, GitInitFailed, NoGitHubRepoNameGiven, NoGitHubToken, NoGitHubUser, NoGitUserEmail, NoGitUserName, Tasks, Version, VersionYmlError
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#gemspec ⇒ Object
readonly
Returns the value of attribute gemspec.
Instance Method Summary collapse
- #build_gem ⇒ Object
-
#bump_major_version(options = {}) ⇒ Object
Bumps the major version.
-
#bump_minor_version(options = {}) ⇒ Object
Bumps the minor version.
-
#bump_patch_version(options = {}) ⇒ Object
Bumps the patch version.
-
#initialize(gemspec, base_dir = '.') ⇒ Jeweler
constructor
A new instance of Jeweler.
- #install_gem ⇒ Object
-
#major_version ⇒ Object
Major version, as defined by the gemspec’s Version module.
-
#minor_version ⇒ Object
Minor version, as defined by the gemspec’s Version module.
-
#patch_version ⇒ Object
Patch version, as defined by the gemspec’s Version module.
- #release ⇒ Object
- #release_tag ⇒ Object
-
#unsafe_parse_gemspec(data = nil) ⇒ Object
parses the project’s gemspec from disk without extra sanity checks.
-
#valid_gemspec? ⇒ Boolean
is the project’s gemspec from disk valid?.
-
#validate_gemspec ⇒ Object
Validates the project’s gemspec from disk in an environment similar to how GitHub would build from it.
-
#version ⇒ Object
Human readable version, which is used in the gemspec.
-
#write_gemspec ⇒ Object
Writes out the gemspec.
-
#write_version(major, minor, patch, options = {}) ⇒ Object
Bumps the version, to the specific major/minor/patch version, writing out the appropriate version.rb, and then reloads it.
Constructor Details
#initialize(gemspec, base_dir = '.') ⇒ Jeweler
Returns a new instance of Jeweler.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jeweler.rb', line 17 def initialize(gemspec, base_dir = '.') raise(GemspecError, "Can't create a Jeweler with a nil gemspec") if gemspec.nil? @gemspec = gemspec @base_dir = base_dir if @gemspec.files.nil? || @gemspec.files.empty? @gemspec.files = FileList["[A-Z]*.*", "{bin,generators,lib,test,spec}/**/*"] end @gemspec.has_rdoc = true @gemspec. << '--inline-source' << '--charset=UTF-8' @gemspec.extra_rdoc_files ||= FileList["[A-Z]*.*"] if File.exists?(File.join(base_dir, '.git')) @repo = Git.open(base_dir) end @version = Jeweler::Version.new(@base_dir) end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
15 16 17 |
# File 'lib/jeweler.rb', line 15 def base_dir @base_dir end |
#gemspec ⇒ Object (readonly)
Returns the value of attribute gemspec.
14 15 16 |
# File 'lib/jeweler.rb', line 14 def gemspec @gemspec end |
Instance Method Details
#build_gem ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/jeweler.rb', line 98 def build_gem parsed_gemspec = unsafe_parse_gemspec() Gem::Builder.new(parsed_gemspec).build pkg_dir = File.join(@base_dir, 'pkg') FileUtils.mkdir_p pkg_dir gem_filename = File.join(@base_dir, parsed_gemspec.file_name) FileUtils.mv gem_filename, pkg_dir end |
#bump_major_version(options = {}) ⇒ Object
Bumps the major version.
1.5.1 -> 2.0.0
142 143 144 145 146 147 148 149 |
# File 'lib/jeweler.rb', line 142 def bump_major_version( = {}) = () @version.bump_major @version.write commit_version if [:commit] end |
#bump_minor_version(options = {}) ⇒ Object
Bumps the minor version.
1.5.1 -> 1.6.0
130 131 132 133 134 135 136 137 |
# File 'lib/jeweler.rb', line 130 def bump_minor_version( = {}) = () @version.bump_minor @version.write commit_version if [:commit] end |
#bump_patch_version(options = {}) ⇒ Object
Bumps the patch version.
1.5.1 -> 1.5.2
118 119 120 121 122 123 124 125 |
# File 'lib/jeweler.rb', line 118 def bump_patch_version( = {}) = () @version.bump_patch @version.write commit_version if [:commit] end |
#install_gem ⇒ Object
109 110 111 112 113 |
# File 'lib/jeweler.rb', line 109 def install_gem command = "sudo gem install #{gem_path}" $stdout.puts "Executing #{command.inspect}:" sh command end |
#major_version ⇒ Object
Major version, as defined by the gemspec’s Version module. For 1.5.3, this would return 1.
39 40 41 |
# File 'lib/jeweler.rb', line 39 def major_version @version.major end |
#minor_version ⇒ Object
Minor version, as defined by the gemspec’s Version module. For 1.5.3, this would return 5.
45 46 47 |
# File 'lib/jeweler.rb', line 45 def minor_version @version.minor end |
#patch_version ⇒ Object
Patch version, as defined by the gemspec’s Version module. For 1.5.3, this would return 5.
51 52 53 |
# File 'lib/jeweler.rb', line 51 def patch_version @version.patch end |
#release ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/jeweler.rb', line 164 def release @repo.checkout('master') raise "Hey buddy, try committing them files first" if any_pending_changes? write_gemspec() @repo.add(gemspec_path) $stdout.puts "Committing #{gemspec_path}" @repo.commit("Regenerated gemspec for version #{version}") $stdout.puts "Pushing master to origin" @repo.push $stdout.puts "Tagging #{release_tag}" @repo.add_tag(release_tag) $stdout.puts "Pushing #{release_tag} to origin" @repo.push('origin', release_tag) end |
#release_tag ⇒ Object
185 186 187 |
# File 'lib/jeweler.rb', line 185 def release_tag @release_tag ||= "v#{version}" end |
#unsafe_parse_gemspec(data = nil) ⇒ Object
parses the project’s gemspec from disk without extra sanity checks
93 94 95 96 |
# File 'lib/jeweler.rb', line 93 def unsafe_parse_gemspec(data = nil) data ||= File.read(gemspec_path) eval(data, binding, gemspec_path) end |
#valid_gemspec? ⇒ Boolean
is the project’s gemspec from disk valid?
88 89 90 |
# File 'lib/jeweler.rb', line 88 def valid_gemspec? gemspec_helper.valid? end |
#validate_gemspec ⇒ Object
Validates the project’s gemspec from disk in an environment similar to how GitHub would build from it. See gist.github.com/16215
76 77 78 79 80 81 82 83 84 |
# File 'lib/jeweler.rb', line 76 def validate_gemspec begin gemspec_helper.parse puts "#{gemspec_path} is valid." rescue Exception => e puts "#{gemspec_path} is invalid. See the backtrace for more details." raise end end |
#version ⇒ Object
Human readable version, which is used in the gemspec.
56 57 58 |
# File 'lib/jeweler.rb', line 56 def version @version.to_s end |
#write_gemspec ⇒ Object
Writes out the gemspec
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jeweler.rb', line 61 def write_gemspec self.refresh_version helper = gemspec_helper do |s| s.version = self.version s.date = Time.now end helper.write puts "Generated: #{helper.path}" end |
#write_version(major, minor, patch, options = {}) ⇒ Object
Bumps the version, to the specific major/minor/patch version, writing out the appropriate version.rb, and then reloads it.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/jeweler.rb', line 152 def write_version(major, minor, patch, = {}) = () @version.update_to major, minor, patch @version.write @gemspec.version = @version.to_s commit_version if [:commit] end |