love 0.0.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/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +9 -0
- data/lib/love.rb +113 -0
- data/love.gemspec +33 -0
- data/tasks/github-gem.rb +361 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
love (0.0.1)
|
|
5
|
+
activesupport
|
|
6
|
+
yajl-ruby
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: http://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activesupport (3.0.3)
|
|
12
|
+
rake (0.8.7)
|
|
13
|
+
yajl-ruby (0.7.8)
|
|
14
|
+
|
|
15
|
+
PLATFORMS
|
|
16
|
+
ruby
|
|
17
|
+
|
|
18
|
+
DEPENDENCIES
|
|
19
|
+
activesupport
|
|
20
|
+
love!
|
|
21
|
+
rake
|
|
22
|
+
yajl-ruby
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2010 Willem van Bergen
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
= Love
|
|
2
|
+
|
|
3
|
+
This library accesses the Tender REST API. It is my ode and thanks to the many
|
|
4
|
+
improvements Aaron Patterson did on ActiveRecord.
|
|
5
|
+
|
|
6
|
+
It is currently read-only, and made especially for scripts that import data from
|
|
7
|
+
Tender to use in your own application. Feel free to fork and add missing API calls.
|
|
8
|
+
|
|
9
|
+
== Why?
|
|
10
|
+
|
|
11
|
+
I previously used HTTParty to connect to the Tender API, but I ran into two issues:
|
|
12
|
+
|
|
13
|
+
* HTTParty's JSON decoding is really slow, and resulted in "stack level too deep"
|
|
14
|
+
exceptions. Love uses yajl to decode JSON instead.
|
|
15
|
+
* Because Tender does not check or convert the encoding of email messages that they
|
|
16
|
+
receive, invalid UTF-8 characters can get into the system, which will break Ruby
|
|
17
|
+
1.9. Love handles character encoding manually, and will replace all the invalid
|
|
18
|
+
UTF-8 characters by the UTF "unknown character" character.
|
|
19
|
+
* I still had to handle paging manually to get all data. Love will automatically
|
|
20
|
+
send multiple requests to get all the pages to iterate over all the available
|
|
21
|
+
objects.
|
|
22
|
+
|
|
23
|
+
== Usage
|
|
24
|
+
|
|
25
|
+
require 'love'
|
|
26
|
+
tender = Love.connect('account', 'api_key')
|
|
27
|
+
|
|
28
|
+
# Loop over all discussions:
|
|
29
|
+
tender.each_discussion do |discussion|
|
|
30
|
+
# your awesome stuff here
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Also available:
|
|
34
|
+
tender.each_users { |c| ... }
|
|
35
|
+
tender.each_queue { |q| ... }
|
|
36
|
+
tender.each_category { |c| ... }
|
|
37
|
+
|
|
38
|
+
== About
|
|
39
|
+
|
|
40
|
+
This library is Written by Willem van Bergen for Shopify, and is MIT licensed.
|
|
41
|
+
|
data/Rakefile
ADDED
data/lib/love.rb
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/https'
|
|
3
|
+
require 'active_support'
|
|
4
|
+
require 'yajl'
|
|
5
|
+
|
|
6
|
+
class Love
|
|
7
|
+
|
|
8
|
+
# Create a custom exception class.
|
|
9
|
+
class Exception < StandardError; end
|
|
10
|
+
|
|
11
|
+
# Class for unauthorized exceptions
|
|
12
|
+
class Unauthorized < Love::Exception; end
|
|
13
|
+
|
|
14
|
+
attr_accessor :logger
|
|
15
|
+
|
|
16
|
+
attr_reader :account
|
|
17
|
+
attr_reader :api_key
|
|
18
|
+
|
|
19
|
+
attr_accessor :sleep_between_requests
|
|
20
|
+
|
|
21
|
+
def initialize(account, api_key, options = {})
|
|
22
|
+
@account, @api_key = account, api_key
|
|
23
|
+
|
|
24
|
+
# Handle options
|
|
25
|
+
@sleep_between_requests = options[:sleep_between_requests] || 0.5
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.connect(account, api_key, options = {})
|
|
29
|
+
new(account, api_key, options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_user(id_or_href, options = {})
|
|
33
|
+
if id_or_href.to_s =~ /(\d+)$/
|
|
34
|
+
get("users/#{$1}", options)
|
|
35
|
+
else
|
|
36
|
+
# TODO: use href
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def get_discussion(id_or_href, options = {})
|
|
42
|
+
if id_or_href.to_s =~ /(\d+)$/
|
|
43
|
+
get("discussions/#{$1}", options)
|
|
44
|
+
else
|
|
45
|
+
# TODO: use href
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def each_category(options = {}, &block)
|
|
51
|
+
buffered_each('categories', 'categories', options, &block)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def each_queue(options = {}, &block)
|
|
55
|
+
buffered_each('queues', 'named_queues', options, &block)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def each_user(options = {}, &block)
|
|
59
|
+
buffered_each('users', 'users', options, &block)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def each_discussion(options = {}, &block)
|
|
63
|
+
buffered_each('discussions', 'discussions', options, &block)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
protected
|
|
67
|
+
|
|
68
|
+
def get(path, options = {})
|
|
69
|
+
url = URI.parse("https://api.tenderapp.com/#{account}/#{path}")
|
|
70
|
+
|
|
71
|
+
logger.debug "GET #{url.to_s}" if logger
|
|
72
|
+
|
|
73
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
74
|
+
http.use_ssl = true
|
|
75
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
76
|
+
|
|
77
|
+
req = Net::HTTP::Get.new(url.path, {
|
|
78
|
+
"Accept" => "application/vnd.tender-v1+json",
|
|
79
|
+
"X-Tender-Auth" => api_key
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
response = http.request(req)
|
|
83
|
+
case response.code
|
|
84
|
+
when /2\d\d/
|
|
85
|
+
converter = Encoding::Converter.new('binary', 'utf-8', :invalid => :replace, :undef => :replace)
|
|
86
|
+
Yajl::Parser.new.parse(converter.convert(response.body))
|
|
87
|
+
when '401'
|
|
88
|
+
raise Love::Unauthorized, "Invalid credentials used!"
|
|
89
|
+
else
|
|
90
|
+
raise Love::Exception, "#{response.cody}: #{response.body}"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def buffered_each(path, list_key, options = {}, &block)
|
|
95
|
+
query_options = {}
|
|
96
|
+
query_options[:since] = options[:since].to_date.to_s(:db) if options[:since]
|
|
97
|
+
|
|
98
|
+
initial_result = get(path, :query => query_options)
|
|
99
|
+
start_page = [options[:start_page].to_i, 1].max rescue 1
|
|
100
|
+
max_page = (initial_result['total'].to_f / initial_result['per_page'].to_f).ceil
|
|
101
|
+
end_page = options[:end_page].nil? ? max_page : [options[:end_page].to_i, max_page].min
|
|
102
|
+
|
|
103
|
+
# Print out some initial debugging information
|
|
104
|
+
|
|
105
|
+
logger.debug "Paged requests to #{path}: #{max_page} total pages, importing #{start_page} upto #{end_page}." if logger
|
|
106
|
+
|
|
107
|
+
start_page.upto(end_page) do |page|
|
|
108
|
+
result = get(path, :query => query_options.merge(:page => page))
|
|
109
|
+
result[list_key].each { |record| yield(record) }
|
|
110
|
+
sleep(sleep_between_requests) if sleep_between_requests
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
data/love.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'love'
|
|
3
|
+
|
|
4
|
+
# Do not change the version and date fields by hand. This will be done
|
|
5
|
+
# automatically by the gem release script.
|
|
6
|
+
s.version = "0.0.1"
|
|
7
|
+
s.date = "2010-11-29"
|
|
8
|
+
|
|
9
|
+
s.summary = "Ruby library to access the Tender REST API."
|
|
10
|
+
s.description = <<-EOT
|
|
11
|
+
A simple API wrapper for Tender, that handles paged results, uses yajl-ruby for
|
|
12
|
+
JSON parsing, and manually handles UTF-8 encoding to circumvent the invalid UTF-8
|
|
13
|
+
character problem in Ruby 1.9.
|
|
14
|
+
EOT
|
|
15
|
+
|
|
16
|
+
s.authors = ['Willem van Bergen']
|
|
17
|
+
s.email = ['willem@railsdoctors.com']
|
|
18
|
+
s.homepage = 'http://github.com/wvanbergen/love'
|
|
19
|
+
|
|
20
|
+
s.add_runtime_dependency('activesupport')
|
|
21
|
+
s.add_runtime_dependency('yajl-ruby')
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency('rake')
|
|
24
|
+
# s.add_development_dependency('rspec', '~> 2.1')
|
|
25
|
+
|
|
26
|
+
s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
|
|
27
|
+
s.extra_rdoc_files = ['README.rdoc']
|
|
28
|
+
|
|
29
|
+
# Do not change the files and test_files fields by hand. This will be done
|
|
30
|
+
# automatically by the gem release script.
|
|
31
|
+
s.files = %w(.gitignore Gemfile Gemfile.lock LICENSE README.rdoc Rakefile lib/love.rb love.gemspec tasks/github-gem.rb)
|
|
32
|
+
s.test_files = %w()
|
|
33
|
+
end
|
data/tasks/github-gem.rb
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/tasklib'
|
|
4
|
+
require 'date'
|
|
5
|
+
require 'set'
|
|
6
|
+
|
|
7
|
+
module GithubGem
|
|
8
|
+
|
|
9
|
+
# Detects the gemspc file of this project using heuristics.
|
|
10
|
+
def self.detect_gemspec_file
|
|
11
|
+
FileList['*.gemspec'].first
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Detects the main include file of this project using heuristics
|
|
15
|
+
def self.detect_main_include
|
|
16
|
+
if detect_gemspec_file =~ /^(\.*)\.gemspec$/ && File.exist?("lib/#{$1}.rb")
|
|
17
|
+
"lib/#{$1}.rb"
|
|
18
|
+
elsif FileList['lib/*.rb'].length == 1
|
|
19
|
+
FileList['lib/*.rb'].first
|
|
20
|
+
else
|
|
21
|
+
nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class RakeTasks
|
|
26
|
+
|
|
27
|
+
attr_reader :gemspec, :modified_files
|
|
28
|
+
attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
|
|
29
|
+
|
|
30
|
+
# Initializes the settings, yields itself for configuration
|
|
31
|
+
# and defines the rake tasks based on the gemspec file.
|
|
32
|
+
def initialize(task_namespace = :gem)
|
|
33
|
+
@gemspec_file = GithubGem.detect_gemspec_file
|
|
34
|
+
@task_namespace = task_namespace
|
|
35
|
+
@main_include = GithubGem.detect_main_include
|
|
36
|
+
@modified_files = Set.new
|
|
37
|
+
@root_dir = Dir.pwd
|
|
38
|
+
@test_pattern = 'test/**/*_test.rb'
|
|
39
|
+
@spec_pattern = 'spec/**/*_spec.rb'
|
|
40
|
+
@local_branch = 'master'
|
|
41
|
+
@remote = 'origin'
|
|
42
|
+
@remote_branch = 'master'
|
|
43
|
+
|
|
44
|
+
yield(self) if block_given?
|
|
45
|
+
|
|
46
|
+
load_gemspec!
|
|
47
|
+
define_tasks!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
protected
|
|
51
|
+
|
|
52
|
+
def git
|
|
53
|
+
@git ||= ENV['GIT'] || 'git'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Define Unit test tasks
|
|
57
|
+
def define_test_tasks!
|
|
58
|
+
require 'rake/testtask'
|
|
59
|
+
|
|
60
|
+
namespace(:test) do
|
|
61
|
+
Rake::TestTask.new(:basic) do |t|
|
|
62
|
+
t.pattern = test_pattern
|
|
63
|
+
t.verbose = true
|
|
64
|
+
t.libs << 'test'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc "Run all unit tests for #{gemspec.name}"
|
|
69
|
+
task(:test => ['test:basic'])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Defines RSpec tasks
|
|
73
|
+
def define_rspec_tasks!
|
|
74
|
+
require 'rspec/core/rake_task'
|
|
75
|
+
|
|
76
|
+
namespace(:spec) do
|
|
77
|
+
desc "Verify all RSpec examples for #{gemspec.name}"
|
|
78
|
+
RSpec::Core::RakeTask.new(:basic) do |t|
|
|
79
|
+
t.pattern = spec_pattern
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
|
|
83
|
+
RSpec::Core::RakeTask.new(:specdoc) do |t|
|
|
84
|
+
t.pattern = spec_pattern
|
|
85
|
+
t.rspec_opts = ['--format', 'documentation', '--color']
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
desc "Run RCov on specs for #{gemspec.name}"
|
|
89
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
|
90
|
+
t.pattern = spec_pattern
|
|
91
|
+
t.rcov = true
|
|
92
|
+
t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
|
|
97
|
+
task(:spec => ['spec:specdoc'])
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Defines the rake tasks
|
|
101
|
+
def define_tasks!
|
|
102
|
+
|
|
103
|
+
define_test_tasks! if has_tests?
|
|
104
|
+
define_rspec_tasks! if has_specs?
|
|
105
|
+
|
|
106
|
+
namespace(@task_namespace) do
|
|
107
|
+
desc "Updates the filelist in the gemspec file"
|
|
108
|
+
task(:manifest) { manifest_task }
|
|
109
|
+
|
|
110
|
+
desc "Builds the .gem package"
|
|
111
|
+
task(:build => :manifest) { build_task }
|
|
112
|
+
|
|
113
|
+
desc "Sets the version of the gem in the gemspec"
|
|
114
|
+
task(:set_version => [:check_version, :check_current_branch]) { version_task }
|
|
115
|
+
task(:check_version => :fetch_origin) { check_version_task }
|
|
116
|
+
|
|
117
|
+
task(:fetch_origin) { fetch_origin_task }
|
|
118
|
+
task(:check_current_branch) { check_current_branch_task }
|
|
119
|
+
task(:check_clean_status) { check_clean_status_task }
|
|
120
|
+
task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
|
|
121
|
+
|
|
122
|
+
checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
|
|
123
|
+
checks.unshift('spec:basic') if has_specs?
|
|
124
|
+
checks.unshift('test:basic') if has_tests?
|
|
125
|
+
# checks.push << [:check_rubyforge] if gemspec.rubyforge_project
|
|
126
|
+
|
|
127
|
+
desc "Perform all checks that would occur before a release"
|
|
128
|
+
task(:release_checks => checks)
|
|
129
|
+
|
|
130
|
+
release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
|
|
131
|
+
# release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
|
|
132
|
+
|
|
133
|
+
desc "Release a new version of the gem using the VERSION environment variable"
|
|
134
|
+
task(:release => release_tasks) { release_task }
|
|
135
|
+
|
|
136
|
+
namespace(:release) do
|
|
137
|
+
desc "Release the next version of the gem, by incrementing the last version segment by 1"
|
|
138
|
+
task(:next => [:next_version] + release_tasks) { release_task }
|
|
139
|
+
|
|
140
|
+
desc "Release the next version of the gem, using a patch increment (0.0.1)"
|
|
141
|
+
task(:patch => [:next_patch_version] + release_tasks) { release_task }
|
|
142
|
+
|
|
143
|
+
desc "Release the next version of the gem, using a minor increment (0.1.0)"
|
|
144
|
+
task(:minor => [:next_minor_version] + release_tasks) { release_task }
|
|
145
|
+
|
|
146
|
+
desc "Release the next version of the gem, using a major increment (1.0.0)"
|
|
147
|
+
task(:major => [:next_major_version] + release_tasks) { release_task }
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# task(:check_rubyforge) { check_rubyforge_task }
|
|
151
|
+
# task(:rubyforge_release) { rubyforge_release_task }
|
|
152
|
+
task(:gemcutter_release) { gemcutter_release_task }
|
|
153
|
+
task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
|
|
154
|
+
task(:tag_version) { tag_version_task }
|
|
155
|
+
task(:commit_modified_files) { commit_modified_files_task }
|
|
156
|
+
|
|
157
|
+
task(:next_version) { next_version_task }
|
|
158
|
+
task(:next_patch_version) { next_version_task(:patch) }
|
|
159
|
+
task(:next_minor_version) { next_version_task(:minor) }
|
|
160
|
+
task(:next_major_version) { next_version_task(:major) }
|
|
161
|
+
|
|
162
|
+
desc "Updates the gem release tasks with the latest version on Github"
|
|
163
|
+
task(:update_tasks) { update_tasks_task }
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Updates the files list and test_files list in the gemspec file using the list of files
|
|
168
|
+
# in the repository and the spec/test file pattern.
|
|
169
|
+
def manifest_task
|
|
170
|
+
# Load all the gem's files using "git ls-files"
|
|
171
|
+
repository_files = `#{git} ls-files`.split("\n")
|
|
172
|
+
test_files = Dir[test_pattern] + Dir[spec_pattern]
|
|
173
|
+
|
|
174
|
+
update_gemspec(:files, repository_files)
|
|
175
|
+
update_gemspec(:test_files, repository_files & test_files)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# Builds the gem
|
|
179
|
+
def build_task
|
|
180
|
+
sh "gem build -q #{gemspec_file}"
|
|
181
|
+
Dir.mkdir('pkg') unless File.exist?('pkg')
|
|
182
|
+
sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def newest_version
|
|
186
|
+
`#{git} tag`.split("\n").map { |tag| tag.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def next_version(increment = nil)
|
|
190
|
+
next_version = newest_version.segments
|
|
191
|
+
increment_index = case increment
|
|
192
|
+
when :micro then 3
|
|
193
|
+
when :patch then 2
|
|
194
|
+
when :minor then 1
|
|
195
|
+
when :major then 0
|
|
196
|
+
else next_version.length - 1
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
next_version[increment_index] ||= 0
|
|
200
|
+
next_version[increment_index] = next_version[increment_index].succ
|
|
201
|
+
((increment_index + 1)...next_version.length).each { |i| next_version[i] = 0 }
|
|
202
|
+
|
|
203
|
+
Gem::Version.new(next_version.join('.'))
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def next_version_task(increment = nil)
|
|
207
|
+
ENV['VERSION'] = next_version(increment).version
|
|
208
|
+
puts "Releasing version #{ENV['VERSION']}..."
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Updates the version number in the gemspec file, the VERSION constant in the main
|
|
212
|
+
# include file and the contents of the VERSION file.
|
|
213
|
+
def version_task
|
|
214
|
+
update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
|
|
215
|
+
update_gemspec(:date, Date.today)
|
|
216
|
+
|
|
217
|
+
update_version_file(gemspec.version)
|
|
218
|
+
update_version_constant(gemspec.version)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def check_version_task
|
|
222
|
+
raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
|
|
223
|
+
proposed_version = Gem::Version.new((ENV['VERSION'] || gemspec.version).dup)
|
|
224
|
+
raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version >= proposed_version
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Checks whether the current branch is not diverged from the remote branch
|
|
228
|
+
def check_not_diverged_task
|
|
229
|
+
raise "The current branch is diverged from the remote branch!" if `#{git} rev-list HEAD..#{remote}/#{remote_branch}`.split("\n").any?
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Checks whether the repository status ic clean
|
|
233
|
+
def check_clean_status_task
|
|
234
|
+
raise "The current working copy contains modifications" if `#{git} ls-files -m`.split("\n").any?
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Checks whether the current branch is correct
|
|
238
|
+
def check_current_branch_task
|
|
239
|
+
raise "Currently not on #{local_branch} branch!" unless `#{git} branch`.split("\n").detect { |b| /^\* / =~ b } == "* #{local_branch}"
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Fetches the latest updates from Github
|
|
243
|
+
def fetch_origin_task
|
|
244
|
+
sh git, 'fetch', remote
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Commits every file that has been changed by the release task.
|
|
248
|
+
def commit_modified_files_task
|
|
249
|
+
really_modified = `#{git} ls-files -m #{modified_files.entries.join(' ')}`.split("\n")
|
|
250
|
+
if really_modified.any?
|
|
251
|
+
really_modified.each { |file| sh git, 'add', file }
|
|
252
|
+
sh git, 'commit', '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# Adds a tag for the released version
|
|
257
|
+
def tag_version_task
|
|
258
|
+
sh git, 'tag', '-a', "#{gemspec.name}-#{gemspec.version}", '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# Pushes the changes and tag to github
|
|
262
|
+
def github_release_task
|
|
263
|
+
sh git, 'push', '--tags', remote, remote_branch
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def gemcutter_release_task
|
|
267
|
+
sh "gem", 'push', "pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Gem release task.
|
|
271
|
+
# All work is done by the task's dependencies, so just display a release completed message.
|
|
272
|
+
def release_task
|
|
273
|
+
puts
|
|
274
|
+
puts "Release successful."
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
private
|
|
278
|
+
|
|
279
|
+
# Checks whether this project has any RSpec files
|
|
280
|
+
def has_specs?
|
|
281
|
+
FileList[spec_pattern].any?
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# Checks whether this project has any unit test files
|
|
285
|
+
def has_tests?
|
|
286
|
+
FileList[test_pattern].any?
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Loads the gemspec file
|
|
290
|
+
def load_gemspec!
|
|
291
|
+
@gemspec = eval(File.read(@gemspec_file))
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Updates the VERSION file with the new version
|
|
295
|
+
def update_version_file(version)
|
|
296
|
+
if File.exists?('VERSION')
|
|
297
|
+
File.open('VERSION', 'w') { |f| f << version.to_s }
|
|
298
|
+
modified_files << 'VERSION'
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Updates the VERSION constant in the main include file if it exists
|
|
303
|
+
def update_version_constant(version)
|
|
304
|
+
if main_include && File.exist?(main_include)
|
|
305
|
+
file_contents = File.read(main_include)
|
|
306
|
+
if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
|
|
307
|
+
File.open(main_include, 'w') { |f| f << file_contents }
|
|
308
|
+
modified_files << main_include
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# Updates an attribute of the gemspec file.
|
|
314
|
+
# This function will open the file, and search/replace the attribute using a regular expression.
|
|
315
|
+
def update_gemspec(attribute, new_value, literal = false)
|
|
316
|
+
|
|
317
|
+
unless literal
|
|
318
|
+
new_value = case new_value
|
|
319
|
+
when Array then "%w(#{new_value.join(' ')})"
|
|
320
|
+
when Hash, String then new_value.inspect
|
|
321
|
+
when Date then new_value.strftime('%Y-%m-%d').inspect
|
|
322
|
+
else raise "Cannot write value #{new_value.inspect} to gemspec file!"
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
spec = File.read(gemspec_file)
|
|
327
|
+
regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
|
|
328
|
+
if spec.sub!(regexp) { $1 + new_value }
|
|
329
|
+
File.open(gemspec_file, 'w') { |f| f << spec }
|
|
330
|
+
modified_files << gemspec_file
|
|
331
|
+
|
|
332
|
+
# Reload the gemspec so the changes are incorporated
|
|
333
|
+
load_gemspec!
|
|
334
|
+
|
|
335
|
+
# Also mark the Gemfile.lock file as changed because of the new version.
|
|
336
|
+
modified_files << 'Gemfile.lock' if File.exist?(File.join(root_dir, 'Gemfile.lock'))
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# Updates the tasks file using the latest file found on Github
|
|
341
|
+
def update_tasks_task
|
|
342
|
+
require 'net/https'
|
|
343
|
+
require 'uri'
|
|
344
|
+
|
|
345
|
+
uri = URI.parse('https://github.com/wvanbergen/github-gem/raw/master/tasks/github-gem.rake')
|
|
346
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
347
|
+
http.use_ssl = true
|
|
348
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
349
|
+
response = http.request(Net::HTTP::Get.new(uri.path))
|
|
350
|
+
|
|
351
|
+
open(__FILE__, "w") { |file| file.write(response.body) }
|
|
352
|
+
relative_file = File.expand_path(__FILE__).sub(%r[^#{@root_dir}/], '')
|
|
353
|
+
if `#{git} ls-files -m #{relative_file}`.split("\n").any?
|
|
354
|
+
sh git, 'add', relative_file
|
|
355
|
+
sh git, 'commit', '-m', "Updated to latest gem release management tasks."
|
|
356
|
+
else
|
|
357
|
+
puts "Release managament tasks already are at the latest version."
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: love
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: 0.0.1
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Willem van Bergen
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-11-29 00:00:00 -05:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: activesupport
|
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
23
|
+
none: false
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 0
|
|
29
|
+
version: "0"
|
|
30
|
+
type: :runtime
|
|
31
|
+
prerelease: false
|
|
32
|
+
version_requirements: *id001
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: yajl-ruby
|
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
36
|
+
none: false
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
segments:
|
|
41
|
+
- 0
|
|
42
|
+
version: "0"
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: *id002
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rake
|
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
segments:
|
|
54
|
+
- 0
|
|
55
|
+
version: "0"
|
|
56
|
+
type: :development
|
|
57
|
+
prerelease: false
|
|
58
|
+
version_requirements: *id003
|
|
59
|
+
description: " A simple API wrapper for Tender, that handles paged results, uses yajl-ruby for\n JSON parsing, and manually handles UTF-8 encoding to circumvent the invalid UTF-8\n character problem in Ruby 1.9.\n"
|
|
60
|
+
email:
|
|
61
|
+
- willem@railsdoctors.com
|
|
62
|
+
executables: []
|
|
63
|
+
|
|
64
|
+
extensions: []
|
|
65
|
+
|
|
66
|
+
extra_rdoc_files:
|
|
67
|
+
- README.rdoc
|
|
68
|
+
files:
|
|
69
|
+
- .gitignore
|
|
70
|
+
- Gemfile
|
|
71
|
+
- Gemfile.lock
|
|
72
|
+
- LICENSE
|
|
73
|
+
- README.rdoc
|
|
74
|
+
- Rakefile
|
|
75
|
+
- lib/love.rb
|
|
76
|
+
- love.gemspec
|
|
77
|
+
- tasks/github-gem.rb
|
|
78
|
+
has_rdoc: true
|
|
79
|
+
homepage: http://github.com/wvanbergen/love
|
|
80
|
+
licenses: []
|
|
81
|
+
|
|
82
|
+
post_install_message:
|
|
83
|
+
rdoc_options:
|
|
84
|
+
- --title
|
|
85
|
+
- love
|
|
86
|
+
- --main
|
|
87
|
+
- README.rdoc
|
|
88
|
+
- --line-numbers
|
|
89
|
+
- --inline-source
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
none: false
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
hash: 1414303505794391607
|
|
98
|
+
segments:
|
|
99
|
+
- 0
|
|
100
|
+
version: "0"
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
none: false
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
hash: 1414303505794391607
|
|
107
|
+
segments:
|
|
108
|
+
- 0
|
|
109
|
+
version: "0"
|
|
110
|
+
requirements: []
|
|
111
|
+
|
|
112
|
+
rubyforge_project:
|
|
113
|
+
rubygems_version: 1.3.7
|
|
114
|
+
signing_key:
|
|
115
|
+
specification_version: 3
|
|
116
|
+
summary: Ruby library to access the Tender REST API.
|
|
117
|
+
test_files: []
|
|
118
|
+
|