adyen 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/Gemfile +5 -0
- data/README.rdoc +5 -1
- data/Rakefile +14 -8
- data/adyen.gemspec +10 -5
- data/lib/adyen.rb +1 -5
- data/lib/adyen/api/cacert.pem +350 -460
- data/lib/adyen/api/response.rb +1 -1
- data/lib/adyen/api/xml_querier.rb +69 -34
- data/lib/adyen/encoding.rb +1 -1
- data/lib/adyen/matchers.rb +7 -15
- data/lib/adyen/version.rb +5 -0
- data/spec/api/spec_helper.rb +4 -4
- data/spec/form_spec.rb +5 -1
- metadata +7 -5
- data/tasks/github-gem.rake +0 -367
data/lib/adyen/api/response.rb
CHANGED
@@ -41,7 +41,7 @@ module Adyen
|
|
41
41
|
|
42
42
|
# @return [XMLQuerier] The response body wrapped in a XMLQuerier.
|
43
43
|
def xml_querier
|
44
|
-
@xml_querier ||= XMLQuerier.
|
44
|
+
@xml_querier ||= XMLQuerier.xml(@http_response.body)
|
45
45
|
end
|
46
46
|
|
47
47
|
# @return [Hash] Subclasses return the parsed response body.
|
@@ -15,43 +15,78 @@ module Adyen
|
|
15
15
|
'common' => 'http://common.services.adyen.com'
|
16
16
|
}
|
17
17
|
|
18
|
-
class
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def document_for_xml(xml)
|
34
|
-
REXML::Document.new(xml)
|
35
|
-
end
|
36
|
-
def perform_xpath(query)
|
37
|
-
REXML::XPath.match(@node, query, NS)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
18
|
+
class NokogiriBackend
|
19
|
+
def initialize
|
20
|
+
require 'nokogiri'
|
21
|
+
end
|
22
|
+
|
23
|
+
def document_for_html(html)
|
24
|
+
Nokogiri::HTML::Document.parse(html, nil, 'UTF-8')
|
25
|
+
end
|
26
|
+
|
27
|
+
def document_for_xml(xml)
|
28
|
+
Nokogiri::XML::Document.parse(xml)
|
29
|
+
end
|
30
|
+
|
31
|
+
def perform_xpath(query, root_node)
|
32
|
+
root_node.xpath(query, NS)
|
41
33
|
end
|
42
34
|
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
36
|
+
class REXMLBackend
|
37
|
+
def initialize
|
38
|
+
require 'rexml/document'
|
39
|
+
end
|
40
|
+
|
41
|
+
def document_for_html(html)
|
42
|
+
REXML::Document.new(html)
|
43
|
+
end
|
44
|
+
|
45
|
+
def document_for_xml(xml)
|
46
|
+
REXML::Document.new(xml)
|
47
|
+
end
|
48
|
+
|
49
|
+
def perform_xpath(query, root_node)
|
50
|
+
REXML::XPath.match(root_node, query, NS)
|
51
|
+
end
|
50
52
|
end
|
51
53
|
|
52
|
-
# @
|
53
|
-
def
|
54
|
-
@
|
54
|
+
# @return A backend to handle XML parsing.
|
55
|
+
def self.default_backend
|
56
|
+
@default_backend ||= begin
|
57
|
+
NokogiriBackend.new
|
58
|
+
rescue LoadError => e
|
59
|
+
REXMLBackend.new
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Creates an XML querier for an XML document
|
64
|
+
def self.xml(data, backend = nil)
|
65
|
+
backend ||= default_backend
|
66
|
+
self.new(backend.document_for_xml(string_from(data)), backend)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Creates an XML querier for an HTML document
|
70
|
+
def self.html(data, backend = nil)
|
71
|
+
backend ||= default_backend
|
72
|
+
self.new(backend.document_for_html(string_from(data)), backend)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.string_from(data)
|
76
|
+
if data.is_a?(String)
|
77
|
+
data
|
78
|
+
elsif data.responds_to?(:body)
|
79
|
+
data.body.to_s
|
80
|
+
else
|
81
|
+
data.to_s
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
attr_reader :backend
|
86
|
+
|
87
|
+
# @param [Nokogiri::XML::NodeSet] data The XML data to wrap.
|
88
|
+
def initialize(node, backend)
|
89
|
+
@node, @backend = node, backend
|
55
90
|
end
|
56
91
|
|
57
92
|
# @param [String] query The xpath query to perform.
|
@@ -59,7 +94,7 @@ module Adyen
|
|
59
94
|
# @return [XMLQuerier] A new XMLQuerier scoped to the given +query+. Or, if a block is given,
|
60
95
|
# the result of calling the block.
|
61
96
|
def xpath(query)
|
62
|
-
result = self.class.new(perform_xpath(query))
|
97
|
+
result = self.class.new(backend.perform_xpath(query, @node), backend)
|
63
98
|
block_given? ? yield(result) : result
|
64
99
|
end
|
65
100
|
|
@@ -87,7 +122,7 @@ module Adyen
|
|
87
122
|
# @yield [XMLQuerier] A member of this node set, ready to be queried.
|
88
123
|
# @return [Array] The list of nodes wrapped in XMLQuerier instances.
|
89
124
|
def map(&block)
|
90
|
-
@node.map { |n| self.class.new(n) }.map(&block)
|
125
|
+
@node.map { |n| self.class.new(n, backend) }.map(&block)
|
91
126
|
end
|
92
127
|
end
|
93
128
|
end
|
data/lib/adyen/encoding.rb
CHANGED
@@ -6,7 +6,7 @@ require 'zlib'
|
|
6
6
|
module Adyen
|
7
7
|
module Encoding
|
8
8
|
def self.hmac_base64(hmac_key, message)
|
9
|
-
digest = OpenSSL::HMAC.digest(OpenSSL::Digest
|
9
|
+
digest = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), hmac_key, message)
|
10
10
|
Base64.encode64(digest).strip
|
11
11
|
end
|
12
12
|
|
data/lib/adyen/matchers.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'rexml/xpath'
|
1
|
+
require 'adyen/api/xml_querier'
|
3
2
|
|
4
3
|
module Adyen
|
5
4
|
module Matchers
|
@@ -30,20 +29,13 @@ module Adyen
|
|
30
29
|
return xpath_query
|
31
30
|
end
|
32
31
|
|
33
|
-
def self.document(subject)
|
34
|
-
if String === subject
|
35
|
-
REXML::Document.new(subject.to_s)
|
36
|
-
elsif subject.respond_to?(:body)
|
37
|
-
REXML::Document.new(subject.body.to_s)
|
38
|
-
elsif REXML::Document === subject
|
39
|
-
subject
|
40
|
-
else
|
41
|
-
raise "Cannot handle this XML input type"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
32
|
def self.check(subject, checks = {})
|
46
|
-
|
33
|
+
found = false
|
34
|
+
document = Adyen::API::XMLQuerier.html(subject)
|
35
|
+
document.xpath(build_xpath_query(checks)) do |result|
|
36
|
+
found = true
|
37
|
+
end
|
38
|
+
return found
|
47
39
|
end
|
48
40
|
end
|
49
41
|
|
data/spec/api/spec_helper.rb
CHANGED
@@ -84,7 +84,7 @@ end
|
|
84
84
|
|
85
85
|
module APISpecHelper
|
86
86
|
def node_for_current_object_and_method
|
87
|
-
Adyen::API::XMLQuerier.
|
87
|
+
Adyen::API::XMLQuerier.xml(@object.send(@method))
|
88
88
|
end
|
89
89
|
|
90
90
|
def xpath(query, &block)
|
@@ -108,10 +108,10 @@ module APISpecHelper
|
|
108
108
|
|
109
109
|
module ClassMethods
|
110
110
|
def for_each_xml_backend(&block)
|
111
|
-
[
|
111
|
+
backends = [Adyen::API::XMLQuerier::NokogiriBackend, Adyen::API::XMLQuerier::REXMLBackend]
|
112
|
+
backends.each do |xml_backend|
|
112
113
|
describe "with a #{xml_backend} backend" do
|
113
|
-
before { Adyen::API::XMLQuerier.
|
114
|
-
after { Adyen::API::XMLQuerier.backend = :nokogiri }
|
114
|
+
before { Adyen::API::XMLQuerier.stub(:default_backend => xml_backend.new) }
|
115
115
|
instance_eval(&block)
|
116
116
|
end
|
117
117
|
end
|
data/spec/form_spec.rb
CHANGED
@@ -139,6 +139,7 @@ describe Adyen::Form do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
describe 'hidden fields generation' do
|
142
|
+
include APISpecHelper
|
142
143
|
subject { %Q'<form action="#{CGI.escapeHTML(Adyen::Form.url)}" method="post">#{Adyen::Form.hidden_fields(@attributes)}</form>' }
|
143
144
|
|
144
145
|
before(:each) do
|
@@ -147,7 +148,10 @@ describe Adyen::Form do
|
|
147
148
|
:session_validity => Time.now + 3600 }
|
148
149
|
end
|
149
150
|
|
150
|
-
|
151
|
+
for_each_xml_backend do
|
152
|
+
it { should have_adyen_payment_form }
|
153
|
+
end
|
154
|
+
|
151
155
|
it { should include('<input type="hidden" name="merchantAccount" value="TestMerchant" />') }
|
152
156
|
|
153
157
|
context "width default_form_params" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/adyen/railtie.rb
|
114
114
|
- lib/adyen/templates/notification_migration.rb
|
115
115
|
- lib/adyen/templates/notification_model.rb
|
116
|
+
- lib/adyen/version.rb
|
116
117
|
- spec/adyen_spec.rb
|
117
118
|
- spec/api/api_spec.rb
|
118
119
|
- spec/api/payment_service_spec.rb
|
@@ -125,7 +126,6 @@ files:
|
|
125
126
|
- spec/functional/api_spec.rb
|
126
127
|
- spec/functional/initializer.rb.sample
|
127
128
|
- spec/spec_helper.rb
|
128
|
-
- tasks/github-gem.rake
|
129
129
|
- yard_extensions.rb
|
130
130
|
homepage: http://github.com/wvanbergen/adyen/wiki
|
131
131
|
licenses:
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
requirements:
|
155
155
|
- Having Nokogiri installed will speed up XML handling when using the SOAP API.
|
156
156
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.0.
|
157
|
+
rubygems_version: 2.0.14
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: Integrate Adyen payment services in your Ruby on Rails application.
|
@@ -165,7 +165,9 @@ test_files:
|
|
165
165
|
- spec/api/recurring_service_spec.rb
|
166
166
|
- spec/api/response_spec.rb
|
167
167
|
- spec/api/simple_soap_client_spec.rb
|
168
|
+
- spec/api/spec_helper.rb
|
168
169
|
- spec/api/test_helpers_spec.rb
|
169
170
|
- spec/form_spec.rb
|
170
171
|
- spec/functional/api_spec.rb
|
171
|
-
|
172
|
+
- spec/functional/initializer.rb.sample
|
173
|
+
- spec/spec_helper.rb
|
data/tasks/github-gem.rake
DELETED
@@ -1,367 +0,0 @@
|
|
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 File.exist?(File.expand_path("../lib/#{File.basename(detect_gemspec_file, '.gemspec').gsub(/-/, '/')}.rb", detect_gemspec_file))
|
17
|
-
"lib/#{File.basename(detect_gemspec_file, '.gemspec').gsub(/-/, '/')}.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
|
-
include Rake::DSL if Rake.const_defined?('DSL')
|
28
|
-
|
29
|
-
attr_reader :gemspec, :modified_files
|
30
|
-
attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
|
31
|
-
|
32
|
-
# Initializes the settings, yields itself for configuration
|
33
|
-
# and defines the rake tasks based on the gemspec file.
|
34
|
-
def initialize(task_namespace = :gem)
|
35
|
-
@gemspec_file = GithubGem.detect_gemspec_file
|
36
|
-
@task_namespace = task_namespace
|
37
|
-
@main_include = GithubGem.detect_main_include
|
38
|
-
@modified_files = Set.new
|
39
|
-
@root_dir = Dir.pwd
|
40
|
-
@test_pattern = 'test/**/*_test.rb'
|
41
|
-
@spec_pattern = 'spec/**/*_spec.rb'
|
42
|
-
@local_branch = 'master'
|
43
|
-
@remote = 'origin'
|
44
|
-
@remote_branch = 'master'
|
45
|
-
|
46
|
-
yield(self) if block_given?
|
47
|
-
|
48
|
-
load_gemspec!
|
49
|
-
define_tasks!
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
def git
|
55
|
-
@git ||= ENV['GIT'] || 'git'
|
56
|
-
end
|
57
|
-
|
58
|
-
# Define Unit test tasks
|
59
|
-
def define_test_tasks!
|
60
|
-
require 'rake/testtask'
|
61
|
-
|
62
|
-
namespace(:test) do
|
63
|
-
Rake::TestTask.new(:basic) do |t|
|
64
|
-
t.pattern = test_pattern
|
65
|
-
t.verbose = true
|
66
|
-
t.libs << 'test'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
desc "Run all unit tests for #{gemspec.name}"
|
71
|
-
task(:test => ['test:basic'])
|
72
|
-
end
|
73
|
-
|
74
|
-
# Defines RSpec tasks
|
75
|
-
def define_rspec_tasks!
|
76
|
-
require 'rspec/core/rake_task'
|
77
|
-
|
78
|
-
namespace(:spec) do
|
79
|
-
desc "Verify all RSpec examples for #{gemspec.name}"
|
80
|
-
RSpec::Core::RakeTask.new(:basic) do |t|
|
81
|
-
t.pattern = spec_pattern
|
82
|
-
end
|
83
|
-
|
84
|
-
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
|
85
|
-
RSpec::Core::RakeTask.new(:specdoc) do |t|
|
86
|
-
t.pattern = spec_pattern
|
87
|
-
t.rspec_opts = ['--format', 'documentation', '--color']
|
88
|
-
end
|
89
|
-
|
90
|
-
desc "Run RCov on specs for #{gemspec.name}"
|
91
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
92
|
-
t.pattern = spec_pattern
|
93
|
-
t.rcov = true
|
94
|
-
t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
|
99
|
-
task(:spec => ['spec:specdoc'])
|
100
|
-
end
|
101
|
-
|
102
|
-
# Defines the rake tasks
|
103
|
-
def define_tasks!
|
104
|
-
|
105
|
-
define_test_tasks! if has_tests?
|
106
|
-
define_rspec_tasks! if has_specs?
|
107
|
-
|
108
|
-
namespace(@task_namespace) do
|
109
|
-
desc "Updates the filelist in the gemspec file"
|
110
|
-
task(:manifest) { manifest_task }
|
111
|
-
|
112
|
-
desc "Builds the .gem package"
|
113
|
-
task(:build => :manifest) { build_task }
|
114
|
-
|
115
|
-
desc "Sets the version of the gem in the gemspec"
|
116
|
-
task(:set_version => [:check_version, :check_current_branch]) { version_task }
|
117
|
-
task(:check_version => :fetch_origin) { check_version_task }
|
118
|
-
|
119
|
-
task(:fetch_origin) { fetch_origin_task }
|
120
|
-
task(:check_current_branch) { check_current_branch_task }
|
121
|
-
task(:check_clean_status) { check_clean_status_task }
|
122
|
-
task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
|
123
|
-
|
124
|
-
checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
|
125
|
-
checks.unshift('spec:basic') if has_specs?
|
126
|
-
checks.unshift('test:basic') if has_tests?
|
127
|
-
# checks.push << [:check_rubyforge] if gemspec.rubyforge_project
|
128
|
-
|
129
|
-
desc "Perform all checks that would occur before a release"
|
130
|
-
task(:release_checks => checks)
|
131
|
-
|
132
|
-
release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
|
133
|
-
# release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
|
134
|
-
|
135
|
-
desc "Release a new version of the gem using the VERSION environment variable"
|
136
|
-
task(:release => release_tasks) { release_task }
|
137
|
-
|
138
|
-
namespace(:release) do
|
139
|
-
desc "Release the next version of the gem, by incrementing the last version segment by 1"
|
140
|
-
task(:next => [:next_version] + release_tasks) { release_task }
|
141
|
-
|
142
|
-
desc "Release the next version of the gem, using a patch increment (0.0.1)"
|
143
|
-
task(:patch => [:next_patch_version] + release_tasks) { release_task }
|
144
|
-
|
145
|
-
desc "Release the next version of the gem, using a minor increment (0.1.0)"
|
146
|
-
task(:minor => [:next_minor_version] + release_tasks) { release_task }
|
147
|
-
|
148
|
-
desc "Release the next version of the gem, using a major increment (1.0.0)"
|
149
|
-
task(:major => [:next_major_version] + release_tasks) { release_task }
|
150
|
-
end
|
151
|
-
|
152
|
-
# task(:check_rubyforge) { check_rubyforge_task }
|
153
|
-
# task(:rubyforge_release) { rubyforge_release_task }
|
154
|
-
task(:gemcutter_release) { gemcutter_release_task }
|
155
|
-
task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
|
156
|
-
task(:tag_version) { tag_version_task }
|
157
|
-
task(:commit_modified_files) { commit_modified_files_task }
|
158
|
-
|
159
|
-
task(:next_version) { next_version_task }
|
160
|
-
task(:next_patch_version) { next_version_task(:patch) }
|
161
|
-
task(:next_minor_version) { next_version_task(:minor) }
|
162
|
-
task(:next_major_version) { next_version_task(:major) }
|
163
|
-
|
164
|
-
desc "Updates the gem release tasks with the latest version on Github"
|
165
|
-
task(:update_tasks) { update_tasks_task }
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# Updates the files list and test_files list in the gemspec file using the list of files
|
170
|
-
# in the repository and the spec/test file pattern.
|
171
|
-
def manifest_task
|
172
|
-
# Load all the gem's files using "git ls-files"
|
173
|
-
repository_files = `#{git} ls-files`.split("\n")
|
174
|
-
test_files = Dir[test_pattern] + Dir[spec_pattern]
|
175
|
-
|
176
|
-
update_gemspec(:files, repository_files)
|
177
|
-
update_gemspec(:test_files, repository_files & test_files)
|
178
|
-
end
|
179
|
-
|
180
|
-
# Builds the gem
|
181
|
-
def build_task
|
182
|
-
sh "gem build -q #{gemspec_file}"
|
183
|
-
Dir.mkdir('pkg') unless File.exist?('pkg')
|
184
|
-
sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
185
|
-
end
|
186
|
-
|
187
|
-
def newest_version
|
188
|
-
`#{git} tag`.split("\n").map { |tag| tag.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
|
189
|
-
end
|
190
|
-
|
191
|
-
def next_version(increment = nil)
|
192
|
-
next_version = newest_version.segments
|
193
|
-
increment_index = case increment
|
194
|
-
when :micro then 3
|
195
|
-
when :patch then 2
|
196
|
-
when :minor then 1
|
197
|
-
when :major then 0
|
198
|
-
else next_version.length - 1
|
199
|
-
end
|
200
|
-
|
201
|
-
next_version[increment_index] ||= 0
|
202
|
-
next_version[increment_index] = next_version[increment_index].succ
|
203
|
-
((increment_index + 1)...next_version.length).each { |i| next_version[i] = 0 }
|
204
|
-
|
205
|
-
Gem::Version.new(next_version.join('.'))
|
206
|
-
end
|
207
|
-
|
208
|
-
def next_version_task(increment = nil)
|
209
|
-
ENV['VERSION'] = next_version(increment).version
|
210
|
-
puts "Releasing version #{ENV['VERSION']}..."
|
211
|
-
end
|
212
|
-
|
213
|
-
# Updates the version number in the gemspec file, the VERSION constant in the main
|
214
|
-
# include file and the contents of the VERSION file.
|
215
|
-
def version_task
|
216
|
-
update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
|
217
|
-
update_gemspec(:date, Date.today)
|
218
|
-
|
219
|
-
update_version_file(gemspec.version)
|
220
|
-
update_version_constant(gemspec.version)
|
221
|
-
end
|
222
|
-
|
223
|
-
def check_version_task
|
224
|
-
raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
|
225
|
-
proposed_version = Gem::Version.new((ENV['VERSION'] || gemspec.version).dup)
|
226
|
-
raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version >= proposed_version
|
227
|
-
end
|
228
|
-
|
229
|
-
# Checks whether the current branch is not diverged from the remote branch
|
230
|
-
def check_not_diverged_task
|
231
|
-
raise "The current branch is diverged from the remote branch!" if `#{git} rev-list HEAD..#{remote}/#{remote_branch}`.split("\n").any?
|
232
|
-
end
|
233
|
-
|
234
|
-
# Checks whether the repository status ic clean
|
235
|
-
def check_clean_status_task
|
236
|
-
raise "The current working copy contains modifications" if `#{git} ls-files -m`.split("\n").any?
|
237
|
-
end
|
238
|
-
|
239
|
-
# Checks whether the current branch is correct
|
240
|
-
def check_current_branch_task
|
241
|
-
raise "Currently not on #{local_branch} branch!" unless `#{git} branch`.split("\n").detect { |b| /^\* / =~ b } == "* #{local_branch}"
|
242
|
-
end
|
243
|
-
|
244
|
-
# Fetches the latest updates from Github
|
245
|
-
def fetch_origin_task
|
246
|
-
sh git, 'fetch', remote
|
247
|
-
end
|
248
|
-
|
249
|
-
# Commits every file that has been changed by the release task.
|
250
|
-
def commit_modified_files_task
|
251
|
-
really_modified = `#{git} ls-files -m #{modified_files.entries.join(' ')}`.split("\n")
|
252
|
-
if really_modified.any?
|
253
|
-
really_modified.each { |file| sh git, 'add', file }
|
254
|
-
sh git, 'commit', '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
# Adds a tag for the released version
|
259
|
-
def tag_version_task
|
260
|
-
sh git, 'tag', '-a', "#{gemspec.name}-#{gemspec.version}", '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
|
261
|
-
end
|
262
|
-
|
263
|
-
# Pushes the changes and tag to github
|
264
|
-
def github_release_task
|
265
|
-
sh git, 'push', '--tags', remote, remote_branch
|
266
|
-
end
|
267
|
-
|
268
|
-
def gemcutter_release_task
|
269
|
-
sh "gem", 'push', "pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
270
|
-
end
|
271
|
-
|
272
|
-
# Gem release task.
|
273
|
-
# All work is done by the task's dependencies, so just display a release completed message.
|
274
|
-
def release_task
|
275
|
-
puts
|
276
|
-
puts "Release successful."
|
277
|
-
end
|
278
|
-
|
279
|
-
private
|
280
|
-
|
281
|
-
# Checks whether this project has any RSpec files
|
282
|
-
def has_specs?
|
283
|
-
FileList[spec_pattern].any?
|
284
|
-
end
|
285
|
-
|
286
|
-
# Checks whether this project has any unit test files
|
287
|
-
def has_tests?
|
288
|
-
FileList[test_pattern].any?
|
289
|
-
end
|
290
|
-
|
291
|
-
# Loads the gemspec file
|
292
|
-
def load_gemspec!
|
293
|
-
@gemspec = eval(File.read(@gemspec_file))
|
294
|
-
end
|
295
|
-
|
296
|
-
# Updates the VERSION file with the new version
|
297
|
-
def update_version_file(version)
|
298
|
-
if File.exists?('VERSION')
|
299
|
-
File.open('VERSION', 'w') { |f| f << version.to_s }
|
300
|
-
modified_files << 'VERSION'
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
# Updates the VERSION constant in the main include file if it exists
|
305
|
-
def update_version_constant(version)
|
306
|
-
if main_include && File.exist?(main_include)
|
307
|
-
file_contents = File.read(main_include)
|
308
|
-
if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
|
309
|
-
File.open(main_include, 'w') { |f| f << file_contents }
|
310
|
-
modified_files << main_include
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
# Updates an attribute of the gemspec file.
|
316
|
-
# This function will open the file, and search/replace the attribute using a regular expression.
|
317
|
-
def update_gemspec(attribute, new_value, literal = false)
|
318
|
-
|
319
|
-
unless literal
|
320
|
-
new_value = case new_value
|
321
|
-
when Array then "%w(#{new_value.join(' ')})"
|
322
|
-
when Hash, String then new_value.inspect
|
323
|
-
when Date then new_value.strftime('%Y-%m-%d').inspect
|
324
|
-
else raise "Cannot write value #{new_value.inspect} to gemspec file!"
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
spec = File.read(gemspec_file)
|
329
|
-
regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
|
330
|
-
if spec.sub!(regexp) { $1 + new_value }
|
331
|
-
File.open(gemspec_file, 'w') { |f| f << spec }
|
332
|
-
modified_files << gemspec_file
|
333
|
-
|
334
|
-
# Reload the gemspec so the changes are incorporated
|
335
|
-
load_gemspec!
|
336
|
-
|
337
|
-
# Also mark the Gemfile.lock file as changed because of the new version.
|
338
|
-
modified_files << 'Gemfile.lock' if File.exist?(File.join(root_dir, 'Gemfile.lock'))
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
# Updates the tasks file using the latest file found on Github
|
343
|
-
def update_tasks_task
|
344
|
-
require 'net/https'
|
345
|
-
require 'uri'
|
346
|
-
|
347
|
-
uri = URI.parse('https://raw.github.com/wvanbergen/github-gem/master/tasks/github-gem.rake')
|
348
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
349
|
-
http.use_ssl = true
|
350
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
351
|
-
response = http.request(Net::HTTP::Get.new(uri.path))
|
352
|
-
|
353
|
-
if Net::HTTPSuccess === response
|
354
|
-
open(__FILE__, "w") { |file| file.write(response.body) }
|
355
|
-
relative_file = File.expand_path(__FILE__).sub(%r[^#{@root_dir}/], '')
|
356
|
-
if `#{git} ls-files -m #{relative_file}`.split("\n").any?
|
357
|
-
sh git, 'add', relative_file
|
358
|
-
sh git, 'commit', '-m', "Updated to latest gem release management tasks."
|
359
|
-
else
|
360
|
-
puts "Release managament tasks already are at the latest version."
|
361
|
-
end
|
362
|
-
else
|
363
|
-
raise "Download failed with HTTP status #{response.code}!"
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|