rookie 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +13 -1
- data/Rakefile +1 -1
- data/lib/rookie.rb +4 -0
- data/lib/rookie/tasks.rb +24 -4
- data/lib/rookie/tasks/console.rb +34 -6
- data/lib/rookie/tasks/gem.rb +44 -12
- data/lib/rookie/tasks/git.rb +38 -6
- data/lib/rookie/version.rb +22 -2
- metadata +10 -10
data/README.markdown
CHANGED
@@ -2,11 +2,23 @@
|
|
2
2
|
|
3
3
|
Simple Rake tasks that make life easier.
|
4
4
|
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
Latest version:
|
8
|
+
|
9
|
+
gem install rookie
|
10
|
+
|
11
|
+
From source:
|
12
|
+
|
13
|
+
git clone git://github.com/matheusmoreira/rookie.git
|
14
|
+
|
15
|
+
# Introduction
|
16
|
+
|
5
17
|
Putting this in your `Rakefile`:
|
6
18
|
|
7
19
|
require 'rookie'
|
8
20
|
|
9
|
-
Rookie::Tasks.new
|
21
|
+
Rookie::Tasks.new('simple.gemspec').define_tasks!
|
10
22
|
|
11
23
|
Gets you a whole set of nice commands to work with your gem. Run `rake -T` for
|
12
24
|
details.
|
data/Rakefile
CHANGED
data/lib/rookie.rb
CHANGED
data/lib/rookie/tasks.rb
CHANGED
@@ -4,31 +4,50 @@ require 'rookie/tasks/git'
|
|
4
4
|
require 'rake/tasklib'
|
5
5
|
|
6
6
|
module Rookie
|
7
|
+
|
8
|
+
# Provides many useful tasks, like the Gem, Git and Console tasks.
|
9
|
+
#
|
10
|
+
# Don't forget to call #define_tasks! after creating an instance of this
|
11
|
+
# class!
|
7
12
|
class Tasks < ::Rake::TaskLib
|
8
13
|
|
9
|
-
|
14
|
+
# The Gem task.
|
15
|
+
attr_accessor :gem
|
16
|
+
|
17
|
+
# The Git task.
|
18
|
+
attr_accessor :git
|
19
|
+
|
20
|
+
# The Console task.
|
21
|
+
attr_accessor :console
|
10
22
|
|
11
|
-
|
23
|
+
# Initializes the tasks with the given gem specification and options.
|
24
|
+
#
|
25
|
+
# Yields the new instance if given a block.
|
26
|
+
def initialize(gemspec, opts = {})
|
12
27
|
self.gem = Tasks::Gem.new gemspec
|
13
28
|
self.git = Tasks::Git.new gem.spec.version.to_s
|
14
29
|
self.console = Tasks::Console.new gem.spec, opts
|
15
30
|
yield self if block_given?
|
16
|
-
define
|
17
31
|
end
|
18
32
|
|
19
|
-
|
33
|
+
# Defines the tasks for all initialized (not +nil+) tasks.
|
34
|
+
def define_tasks!
|
20
35
|
setup_tasks, clean_tasks, release_tasks = [], [], []
|
21
36
|
|
22
37
|
if git
|
38
|
+
git.define_tasks!
|
23
39
|
release_tasks << 'git:release'
|
24
40
|
end
|
25
41
|
|
26
42
|
if gem
|
43
|
+
gem.define_tasks!
|
27
44
|
setup_tasks << 'gem:setup'
|
28
45
|
clean_tasks << 'gem:clean'
|
29
46
|
release_tasks << 'gem:release'
|
30
47
|
end
|
31
48
|
|
49
|
+
console.define_tasks! if console
|
50
|
+
|
32
51
|
desc 'Setup project'
|
33
52
|
task :setup => setup_tasks
|
34
53
|
|
@@ -42,4 +61,5 @@ module Rookie
|
|
42
61
|
end
|
43
62
|
|
44
63
|
end
|
64
|
+
|
45
65
|
end
|
data/lib/rookie/tasks/console.rb
CHANGED
@@ -2,32 +2,59 @@ require 'rake/tasklib'
|
|
2
2
|
|
3
3
|
module Rookie
|
4
4
|
class Tasks < ::Rake::TaskLib
|
5
|
+
|
6
|
+
# This task provides an easy way to interactively test your gem by
|
7
|
+
# automatically loading and requiring it in an interactive ruby session.
|
5
8
|
class Console < ::Rake::TaskLib
|
6
9
|
|
7
|
-
|
10
|
+
# The gem specification.
|
11
|
+
attr_accessor :spec
|
12
|
+
|
13
|
+
# The name of the program to invoke.
|
14
|
+
attr_accessor :program
|
15
|
+
|
16
|
+
# The full command to execute.
|
8
17
|
attr_writer :command
|
9
18
|
|
19
|
+
# Unless set explicitly, will be automatically generated from the #program
|
20
|
+
# name and gem specification.
|
10
21
|
def command
|
11
22
|
@command ||= generate_command_string
|
12
23
|
end
|
13
24
|
|
25
|
+
# Creates a new console task with the given parameters. Options may
|
26
|
+
# specify:
|
27
|
+
#
|
28
|
+
# [:program] the name of the program to invoke; +irb+ by default.
|
29
|
+
# [:command] the full command to execute. Use if the command you want to
|
30
|
+
# run doesn't take the <tt>-I</tt> and <tt>-r</tt> command
|
31
|
+
# line arguments.
|
32
|
+
#
|
33
|
+
# Yields the instance if given a block.
|
34
|
+
#
|
35
|
+
# Tasks do not get defined automatically; don't forget to call
|
36
|
+
# #define_tasks!
|
14
37
|
def initialize(spec, opts = {})
|
15
38
|
self.spec = spec
|
16
|
-
self.program = opts.fetch :program,
|
39
|
+
self.program = opts.fetch :program, :irb
|
17
40
|
self.command = opts.fetch :command, nil
|
18
41
|
yield self if block_given?
|
19
|
-
define
|
20
42
|
end
|
21
43
|
|
22
|
-
|
23
|
-
|
44
|
+
# Defines the console task.
|
45
|
+
def define_tasks!
|
46
|
+
desc 'Starts an interactive ruby session with the gem loaded'
|
24
47
|
task :console do
|
25
48
|
sh command
|
26
49
|
end
|
27
50
|
end
|
28
51
|
|
52
|
+
# Generates a command string from this task's #program name and gem
|
53
|
+
# specification. For example:
|
54
|
+
#
|
55
|
+
# irb -I lib -r gem_name
|
29
56
|
def generate_command_string
|
30
|
-
program.dup.tap do |command_string|
|
57
|
+
program.to_s.dup.tap do |command_string|
|
31
58
|
spec.require_paths.each do |path|
|
32
59
|
command_string << ' -I ' << path
|
33
60
|
end
|
@@ -36,5 +63,6 @@ module Rookie
|
|
36
63
|
end
|
37
64
|
|
38
65
|
end
|
66
|
+
|
39
67
|
end
|
40
68
|
end
|
data/lib/rookie/tasks/gem.rb
CHANGED
@@ -1,54 +1,84 @@
|
|
1
|
-
require 'rake/tasklib'
|
2
1
|
require 'fileutils'
|
2
|
+
require 'rake/tasklib'
|
3
3
|
|
4
4
|
module Rookie
|
5
5
|
class Tasks < ::Rake::TaskLib
|
6
|
+
|
7
|
+
# Adds various gem management tasks that allows you to build, install,
|
8
|
+
# uninstall and release your gem with ease.
|
6
9
|
class Gem < ::Rake::TaskLib
|
7
10
|
|
8
|
-
|
11
|
+
# The gem specification.
|
12
|
+
attr_reader :spec
|
9
13
|
|
14
|
+
# The directory where <tt>.gem</tt> files will be stored. <tt>'gem'</tt>
|
15
|
+
# by default.
|
16
|
+
#
|
17
|
+
# This directory will be completely erased by the +clean+ task. Make sure
|
18
|
+
# it is not in use!
|
19
|
+
attr_reader :dir
|
20
|
+
|
21
|
+
# Sets this task's gem specification. Loads it from a file if given a
|
22
|
+
# string.
|
10
23
|
def spec=(gemspec)
|
11
24
|
@spec = case gemspec
|
12
|
-
when ::Gem::Specification
|
13
|
-
|
14
|
-
|
15
|
-
::Gem::Specification.load gemspec if gemspec and File.readable? gemspec
|
16
|
-
else
|
17
|
-
nil
|
25
|
+
when ::Gem::Specification then gemspec
|
26
|
+
when String then ::Gem::Specification.load gemspec if File.readable? gemspec
|
27
|
+
else nil
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
31
|
+
# The directory where packaged gems will be stored. Always relative to the
|
32
|
+
# current directory.
|
33
|
+
#
|
34
|
+
# This directory will be completely erased by the +clean+ task. Make sure
|
35
|
+
# it is not in use!
|
21
36
|
def dir=(dir)
|
22
37
|
@dir = File.expand_path File.join(Dir.pwd, dir)
|
23
38
|
end
|
24
39
|
|
40
|
+
# Creates a new gem task with the given gem specification and temporary
|
41
|
+
# gem directory.
|
42
|
+
#
|
43
|
+
# Tasks do not get defined automatically; don't forget to call
|
44
|
+
# #define_tasks!
|
25
45
|
def initialize(gemspec = nil, gem_dir = 'gem')
|
26
46
|
self.spec = gemspec
|
27
47
|
self.dir = gem_dir
|
28
48
|
yield self if block_given?
|
29
|
-
define
|
30
49
|
end
|
31
50
|
|
51
|
+
# The name of the packaged gem file.
|
52
|
+
def gem_file_name
|
53
|
+
"#{spec.name}-#{spec.version}.gem"
|
54
|
+
end
|
55
|
+
|
56
|
+
# The full path to the gem file.
|
32
57
|
def gem_file
|
33
|
-
File.join dir,
|
58
|
+
File.join dir, gem_file_name
|
34
59
|
end
|
35
60
|
|
61
|
+
# Builds the gem from the specification and moves it to the gem directory.
|
36
62
|
def build_gem
|
37
63
|
FileUtils.mkdir_p dir
|
38
64
|
gem = ::Gem::Builder.new(spec).build
|
39
65
|
FileUtils.mv gem, dir
|
40
66
|
end
|
41
67
|
|
68
|
+
# Executes a gem command.
|
42
69
|
def gem(cmd, arg = gem_file)
|
43
70
|
"gem #{cmd} #{arg}"
|
44
71
|
end
|
45
72
|
|
73
|
+
# Removes the gem directory.
|
46
74
|
def clean!
|
47
75
|
FileUtils.rm_rf dir
|
48
76
|
end
|
49
77
|
|
50
|
-
|
78
|
+
# Defines the gem tasks.
|
79
|
+
def define_tasks!
|
51
80
|
directory dir
|
81
|
+
|
52
82
|
namespace :gem do
|
53
83
|
desc 'Builds the gem from the specification'
|
54
84
|
task :build => dir do
|
@@ -60,7 +90,7 @@ module Rookie
|
|
60
90
|
sh gem :push
|
61
91
|
end
|
62
92
|
|
63
|
-
desc 'Same as gem:
|
93
|
+
desc 'Same as gem:push'
|
64
94
|
task :release => :push
|
65
95
|
|
66
96
|
desc 'Installs the gem locally'
|
@@ -81,10 +111,12 @@ module Rookie
|
|
81
111
|
desc 'Installs the gem locally and cleans up'
|
82
112
|
task :setup => [ :install, :clean ]
|
83
113
|
end
|
114
|
+
|
84
115
|
desc 'Same as gem:build'
|
85
116
|
task :gem => 'gem:build'
|
86
117
|
end
|
87
118
|
|
88
119
|
end
|
120
|
+
|
89
121
|
end
|
90
122
|
end
|
data/lib/rookie/tasks/git.rb
CHANGED
@@ -4,29 +4,49 @@ require 'rake/tasklib'
|
|
4
4
|
|
5
5
|
module Rookie
|
6
6
|
class Tasks < ::Rake::TaskLib
|
7
|
+
|
8
|
+
# This task provides a way to quickly and easily release git projects using
|
9
|
+
# a gem specification.
|
7
10
|
class Git < ::Rake::TaskLib
|
8
11
|
|
9
|
-
|
12
|
+
# The version the project will be released under.
|
13
|
+
attr_accessor :release_version
|
14
|
+
|
15
|
+
# Directory which contains the git repository.
|
16
|
+
attr_accessor :working_directory
|
17
|
+
|
18
|
+
# Logger which will be used to log the git messages. Logs to SDTOUT by
|
19
|
+
# default.
|
10
20
|
attr_writer :logger
|
11
21
|
|
22
|
+
# Lazily created logger.
|
12
23
|
def logger
|
13
24
|
@logger ||= create_logger
|
14
25
|
end
|
15
26
|
|
27
|
+
# Creates a new git task with the given parameters. Yields the instance
|
28
|
+
# if given a block.
|
29
|
+
#
|
30
|
+
# Tasks do not get defined automatically; don't forget to call
|
31
|
+
# #define_tasks!
|
16
32
|
def initialize(release_version = nil, working_dir = Dir.pwd, logger = nil)
|
17
33
|
self.logger = logger
|
18
34
|
self.working_directory = working_dir
|
19
35
|
self.release_version = release_version
|
20
36
|
yield self if block_given?
|
21
|
-
define
|
22
37
|
end
|
23
38
|
|
39
|
+
# Computes a release tag for the given version.
|
24
40
|
def release_tag(version = release_version)
|
25
|
-
"v#{version
|
41
|
+
"v#{version}"
|
26
42
|
end
|
27
43
|
|
44
|
+
# Tags the latest commit in the repository with the given tag name.
|
45
|
+
#
|
46
|
+
# If the tag is invalid or already in the repository, an error will be
|
47
|
+
# raised prior to tagging.
|
28
48
|
def tag!(tag_name)
|
29
|
-
raise "Tag '#{tag_name
|
49
|
+
raise "Tag '#{tag_name}' is invalid" if tag_name.nil? or tag_name.empty?
|
30
50
|
if already_tagged? tag_name
|
31
51
|
raise "Tag '#{tag_name}' already in repository"
|
32
52
|
else
|
@@ -34,20 +54,29 @@ module Rookie
|
|
34
54
|
end
|
35
55
|
end
|
36
56
|
|
57
|
+
# Pushes the changes in the given branch to the given remote repository.
|
58
|
+
#
|
59
|
+
# Tags will be pushed too if +tags+ is +true+.
|
37
60
|
def push!(remote = 'origin', branch = 'master', tags = false)
|
38
61
|
git.push remote, branch, tags
|
39
62
|
end
|
40
63
|
|
64
|
+
# Tags the latest commit with the given version tag and pushes the given
|
65
|
+
# branch to the given remote repository, including tags.
|
41
66
|
def release!(version_tag = release_tag, remote = 'origin', branch = 'master')
|
42
67
|
tag! version_tag
|
43
68
|
push! remote, branch, true
|
44
69
|
end
|
45
70
|
|
71
|
+
# Returns whether the repository already contains the given tag name.
|
46
72
|
def already_tagged?(tag_name)
|
47
|
-
git.tag tag_name
|
73
|
+
git.tag tag_name
|
74
|
+
rescue ::Git::GitTagNameDoesNotExist
|
75
|
+
false
|
48
76
|
end
|
49
77
|
|
50
|
-
|
78
|
+
# Defines the git tasks.
|
79
|
+
def define_tasks!
|
51
80
|
namespace :git do
|
52
81
|
desc 'Tags latest commit with the given tag name'
|
53
82
|
task :tag, :tag_name do |task, args|
|
@@ -78,10 +107,12 @@ module Rookie
|
|
78
107
|
|
79
108
|
protected
|
80
109
|
|
110
|
+
# Lazily created git handle. Uses the logger returned by #logger.
|
81
111
|
def git
|
82
112
|
@git ||= ::Git.open working_directory, :log => logger
|
83
113
|
end
|
84
114
|
|
115
|
+
# Creates a logger to STDOUT at INFO level with a custom formatter.
|
85
116
|
def create_logger
|
86
117
|
::Logger.new(STDOUT).tap do |logger|
|
87
118
|
logger.level = ::Logger::INFO
|
@@ -90,5 +121,6 @@ module Rookie
|
|
90
121
|
end
|
91
122
|
|
92
123
|
end
|
124
|
+
|
93
125
|
end
|
94
126
|
end
|
data/lib/rookie/version.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
1
|
module Rookie
|
2
|
+
|
3
|
+
# Rookie's version.
|
2
4
|
module Version
|
3
5
|
|
6
|
+
# Major version.
|
7
|
+
#
|
8
|
+
# Increments denote backward-incompatible changes and additions.
|
4
9
|
MAJOR = 0
|
5
|
-
|
6
|
-
|
10
|
+
|
11
|
+
# Minor version.
|
12
|
+
#
|
13
|
+
# Increments denote backward-compatible changes and additions.
|
14
|
+
MINOR = 3
|
15
|
+
|
16
|
+
# Patch version.
|
17
|
+
#
|
18
|
+
# Increments denote changes in implementation.
|
19
|
+
PATCH = 0
|
20
|
+
|
21
|
+
# Build version.
|
22
|
+
#
|
23
|
+
# Used for pre-release versions.
|
7
24
|
BUILD = nil
|
8
25
|
|
26
|
+
# Complete version string, which is every individual version number joined
|
27
|
+
# by a dot (<tt>'.'</tt>), in descending order of prescedence.
|
9
28
|
STRING = [ MAJOR, MINOR, PATCH, BUILD ].compact.join '.'
|
10
29
|
|
11
30
|
end
|
31
|
+
|
12
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rookie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &12451360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *12451360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: git
|
27
|
-
requirement: &
|
27
|
+
requirement: &12453220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *12453220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &12455200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *12455200
|
47
47
|
description: Simple Rake tasks that make life easier.
|
48
48
|
email: matheus.a.m.moreira@gmail.com
|
49
49
|
executables: []
|
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
segments:
|
80
80
|
- 0
|
81
|
-
hash: -
|
81
|
+
hash: -1447020639505331606
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
segments:
|
89
89
|
- 0
|
90
|
-
hash: -
|
90
|
+
hash: -1447020639505331606
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
93
|
rubygems_version: 1.8.10
|