vcr-archive 0.2.0 → 0.3.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/README.md +2 -1
- data/lib/vcr/archive/version.rb +1 -1
- data/lib/vcr/archive.rb +48 -67
- data/vcr-archive.gemspec +2 -0
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5228f750fa913d827a1bd296a0a4f6cc90d79609
|
4
|
+
data.tar.gz: dc82326c218702636850f6f5e034a94be9e8c199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fd3b2e7b7d8f3819a9e4831dec43e5fb6f79be3a1b8d2a0990f0016f5ec5caaff6f941b041c2cf5585f4096d2c1af303df6df866e08779f1a9129d884abaaa9
|
7
|
+
data.tar.gz: a07c32c19df1ac6f150b274c67cb7f3a36f4a46354b3c375a95ef2e383900c5f64bc2383cf383afe4debe544c7de57f5d0afb679b5aac63dadd5eebda7efc285
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/vcr/archive/version.rb
CHANGED
data/lib/vcr/archive.rb
CHANGED
@@ -1,102 +1,83 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
2
|
|
3
3
|
require 'vcr/archive/version'
|
4
4
|
|
5
5
|
module VCR
|
6
6
|
module Archive
|
7
|
+
module Serializer
|
8
|
+
extend self
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :git_repository_url
|
11
|
-
|
12
|
-
class Serializer
|
13
|
-
def self.file_extension
|
14
|
-
'git'
|
10
|
+
def file_extension
|
11
|
+
'archive'
|
15
12
|
end
|
16
13
|
|
17
|
-
def
|
14
|
+
def serialize(hash)
|
18
15
|
hash
|
19
16
|
end
|
20
17
|
|
21
|
-
def
|
18
|
+
def deserialize(hash)
|
22
19
|
hash
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
23
|
module Persister
|
28
24
|
extend self
|
29
25
|
|
30
|
-
|
31
|
-
nil
|
32
|
-
end
|
26
|
+
attr_reader :storage_location
|
33
27
|
|
34
|
-
def
|
35
|
-
|
28
|
+
def storage_location=(dir)
|
29
|
+
FileUtils.mkdir_p(dir) if dir
|
30
|
+
@storage_location = dir ? absolute_path_for(dir) : nil
|
36
31
|
end
|
37
32
|
|
38
|
-
def
|
39
|
-
|
33
|
+
def [](file_name)
|
34
|
+
path = absolute_path_to_file(file_name)
|
35
|
+
files = Dir.glob("#{path}/**/*.yml")
|
36
|
+
return nil unless files.any?
|
37
|
+
interactions = files.map do |f|
|
38
|
+
meta = YAML.load_file(f)
|
39
|
+
body = File.binread(f.sub(/\.yml$/, '.html'))
|
40
|
+
meta['response']['body']['string'] = body
|
41
|
+
meta
|
42
|
+
end
|
43
|
+
{
|
44
|
+
'http_interactions' => interactions,
|
45
|
+
}
|
40
46
|
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module GitRepository
|
44
|
-
extend self
|
45
47
|
|
46
|
-
def
|
47
|
-
|
48
|
+
def []=(file_name, meta)
|
49
|
+
path = absolute_path_to_file(file_name)
|
50
|
+
meta['http_interactions'].each do |interaction|
|
51
|
+
uri = URI.parse(interaction['request']['uri'])
|
52
|
+
path = File.join(path, uri.host, Digest::SHA1.hexdigest(uri.to_s))
|
53
|
+
directory = File.dirname(path)
|
54
|
+
FileUtils.mkdir_p(directory) unless File.exist?(directory)
|
55
|
+
body = interaction['response']['body'].delete('string')
|
56
|
+
File.binwrite("#{path}.yml", YAML.dump(interaction))
|
57
|
+
File.binwrite("#{path}.html", body)
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
|
-
def
|
51
|
-
|
61
|
+
def absolute_path_to_file(file_name)
|
62
|
+
return nil unless storage_location
|
63
|
+
File.join(storage_location, sanitized_file_name_from(file_name))
|
52
64
|
end
|
53
65
|
|
54
|
-
|
55
|
-
VCR::Archive.git_repository_url
|
56
|
-
end
|
66
|
+
private
|
57
67
|
|
58
|
-
def
|
59
|
-
|
68
|
+
def absolute_path_for(path)
|
69
|
+
Dir.chdir(path) { Dir.pwd }
|
60
70
|
end
|
61
71
|
|
62
|
-
def
|
63
|
-
|
64
|
-
system("git clone --quiet #{git_repository_url} #{directory}")
|
65
|
-
end
|
66
|
-
Dir.chdir(directory) do
|
67
|
-
if system("git rev-parse --verify origin/#{branch_name} > /dev/null 2>&1")
|
68
|
-
system("git checkout --quiet #{branch_name}")
|
69
|
-
else
|
70
|
-
system("git checkout --orphan #{branch_name}")
|
71
|
-
system("git rm --quiet -rf .")
|
72
|
-
end
|
73
|
-
|
74
|
-
yield(directory)
|
75
|
-
|
76
|
-
system("git add .")
|
77
|
-
system("git commit --quiet --allow-empty --message='#{message}'")
|
78
|
-
system("git push --quiet origin #{branch_name}")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
72
|
+
def sanitized_file_name_from(file_name)
|
73
|
+
parts = file_name.to_s.split('.')
|
82
74
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
config.cassette_persisters[:vcr_archive] = Persister
|
87
|
-
config.default_cassette_options = { serialize_with: :vcr_archive, persist_with: :vcr_archive, record: :all }
|
88
|
-
config.before_record do |interaction, cassette|
|
89
|
-
uri = URI.parse(interaction.request.uri)
|
90
|
-
message = "#{interaction.response.status.to_hash.values_at('code', 'message').join(' ')} #{uri}"
|
91
|
-
GitRepository.commit_all(message) do |directory|
|
92
|
-
path = File.join(directory, uri.host, Digest::SHA1.hexdigest(uri.to_s))
|
93
|
-
directory = File.dirname(path)
|
94
|
-
FileUtils.mkdir_p(directory) unless File.exist?(directory)
|
95
|
-
meta = interaction.to_hash
|
96
|
-
body = meta['response']['body'].delete('string')
|
97
|
-
File.binwrite("#{path}.yml", YAML.dump(meta))
|
98
|
-
File.binwrite("#{path}.html", body)
|
75
|
+
# Get rid of the unneeded extension on the file_name
|
76
|
+
if parts.size > 1 && parts.last == Serializer.file_extension
|
77
|
+
parts.pop
|
99
78
|
end
|
79
|
+
|
80
|
+
parts.join('.').gsub(/[^\w\-\/]+/, '_')
|
100
81
|
end
|
101
82
|
end
|
102
83
|
end
|
data/vcr-archive.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
26
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.12.0'
|
27
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcr-archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Mytton
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.12.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.12.0
|
83
111
|
description:
|
84
112
|
email:
|
85
113
|
- chrismytton@gmail.com
|
@@ -113,9 +141,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
141
|
version: '0'
|
114
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
143
|
requirements:
|
116
|
-
- - "
|
144
|
+
- - ">"
|
117
145
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
146
|
+
version: 1.3.1
|
119
147
|
requirements: []
|
120
148
|
rubyforge_project:
|
121
149
|
rubygems_version: 2.5.1
|