yaggy 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/yaggy/gem.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'yaggy/mock_spec'
2
+
3
+ module Yaggy
4
+ class Gem
5
+ def initialize(file, options)
6
+ @gemspec = file
7
+ @options = options
8
+ query_gemspec
9
+ end
10
+
11
+ def use_git?
12
+ if @options.key?(:git_ops)
13
+ @options[:git_ops]
14
+ else
15
+ File.directory?(File.dirname(@gemspec) + "/.git")
16
+ end
17
+ end
18
+
19
+ def commit!
20
+ system("git add #{@gemspec}")
21
+ system("git commit -m 'version #{version}'")
22
+ system("git tag v#{version}")
23
+ system("git push --all --tags") unless %x{git remote}.chomp.empty?
24
+ end
25
+
26
+ def query_gemspec
27
+ mock_spec = Yaggy::MockSpec.capture_gemspec_info(@gemspec)
28
+ version = mock_spec.version
29
+ @version_line = mock_spec.version_line
30
+ @original_version = version
31
+ @major, @minor, @patch = version.split('.')
32
+ @name = mock_spec.name
33
+ end
34
+
35
+ def version
36
+ [major, minor, patch].join('.')
37
+ end
38
+
39
+ def rev_patch!
40
+ @patch = (@patch.to_i + 1).to_s
41
+ end
42
+
43
+ def rev_minor!
44
+ @minor = (@minor.to_i + 1).to_s
45
+ @patch = "0"
46
+ end
47
+
48
+ def rev_major!
49
+ @major = (@major.to_i + 1).to_s
50
+ @minor = "0"
51
+ @patch = "0"
52
+ end
53
+
54
+ def write!
55
+ lines = File.readlines(@gemspec)
56
+ if lines[@version_line - 1] !~ /#{@original_version}/
57
+ raise "Couldn't find version in gemspec."
58
+ end
59
+
60
+ lines[@version_line - 1].sub!(@original_version, version)
61
+ File.open(@gemspec, "w") { |f|
62
+ f.write(lines.join)
63
+ }
64
+ end
65
+
66
+ attr_reader :major, :minor, :patch, :name
67
+ end
68
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rubygems/specification'
3
+
4
+ module Yaggy
5
+ class MockSpec
6
+ def method_missing(*args, &block)
7
+ end
8
+
9
+ def initialize
10
+ yield self
11
+ @@gems[@@current_file] = self
12
+ end
13
+
14
+ attr_reader :version, :version_line
15
+
16
+ def version=(v)
17
+ @version_line = caller.detect { |l| l !~ /#{__FILE__}/ }.split(":")[1].to_i
18
+ @version = v
19
+ end
20
+
21
+ attr_accessor :name
22
+
23
+ def self.capture_gemspec_info(gemspec)
24
+ @@gems ||= {}
25
+ @@current_file = gemspec
26
+ old_verbose, $VERBOSE = $VERBOSE, nil
27
+ old_spec = ::Gem::Specification
28
+ ::Gem.const_set("Specification", ::Yaggy::MockSpec)
29
+ load gemspec
30
+ @@gems[@@current_file]
31
+ ensure
32
+ Gem.const_set("Specification", ::Yaggy::MockSpec)
33
+ $VERBOSE = old_verbose
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module Yaggy
2
+ class Release
3
+ class << self
4
+ def release(what)
5
+ gem = Yaggy.current_gem
6
+ gem.send("rev_#{what}!")
7
+ puts("Releasing #{gem.name} version #{gem.version}")
8
+ gem.write!
9
+ if gem.use_git?
10
+ gem.commit!
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+
@@ -0,0 +1,14 @@
1
+ require 'rake'
2
+
3
+ namespace :release do
4
+ task :patch do
5
+ Yaggy::Release.release(:patch)
6
+ end
7
+ task :minor do
8
+ Yaggy::Release.release(:minor)
9
+ end
10
+ task :major do
11
+ Yaggy::Release.release(:major)
12
+ end
13
+ end
14
+ task :release => "release:patch"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -85,6 +85,10 @@ extra_rdoc_files:
85
85
  files:
86
86
  - README.md
87
87
  - lib/yaggy.rb
88
+ - lib/yaggy/gem.rb
89
+ - lib/yaggy/mock_spec.rb
90
+ - lib/yaggy/release.rb
91
+ - lib/yaggy/tasks.rb
88
92
  homepage: http://github.com/osheroff/yaggy
89
93
  licenses: []
90
94
  post_install_message: