omnijack 0.1.2 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b2ea25f171c43615082dfb66ccd2bfd0f346a0e
4
- data.tar.gz: d4de55724f7cb930ad934fb54e4fdd6a0f0d324a
3
+ metadata.gz: fc253a8a3bc6dae6c9ab5ca28a1af127cbf8ca98
4
+ data.tar.gz: 2886b763948b3e3b01d4ca1843b15588f1ee2717
5
5
  SHA512:
6
- metadata.gz: 190febeaa0f43effe2c66abe12531be60527a3a30331fc6e8d380bfaf7393ee70cf1b46a4f46df86f8a50b441565442bf0f15ea465b1280e13c95f38b70d0698
7
- data.tar.gz: 647e33c31230fa4a2079da35dd1aff2ce70574ae1bc48d1518e54237e1fb97297f254d267f0f32d53796a68e6c68acbead9a0ee2551ff5a030d8b5c80c20e04c
6
+ metadata.gz: 8abff1f3f1bd23af2a420c9718425afc7b2adb65df2e42c5d585d56b3209a8b00a1c78bc69886ccddd1af29206ca8f29d5e2cd402b28ffa8cb43d2c5f243302d
7
+ data.tar.gz: 085621d8d7d5cce42cc519b56847cfab0a80df7446a8f755adbf2d2f0ddcf8c0e458a1a3922f78cd4f48db3b1489f1c3fa656de10640fe9bb0a0e6228189ecd0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Omnijack Gem CHANGELOG
2
2
  ======================
3
3
 
4
+ v0.2.0 (2014-09-19)
5
+ -------------------
6
+ - Calculate and expose version and build numbers as part of metadata
7
+ - Populate project metadata immediately instead of the first time
8
+ `metadata.to_h` is called
9
+ - Remove version string validation to allow for nightly build versions
10
+
4
11
  v0.1.2 (2014-09-17)
5
12
  -------------------
6
13
  - Fix encoding issue with incorrect filename for nightly build packages
data/README.md CHANGED
@@ -51,12 +51,16 @@ puts metadata.filename
51
51
  puts metadata.md5
52
52
  puts metadata.sha256
53
53
  puts metadata.yolo
54
+ puts metadata.version
55
+ puts metadata.build
54
56
 
55
57
  puts metadata[:url]
56
58
  puts metadata[:filename]
57
59
  puts metadata[:md5]
58
60
  puts metadata[:sha256]
59
61
  puts metadata[:yolo]
62
+ puts metadata[:version]
63
+ puts metadata[:build]
60
64
  ```
61
65
  Getting Chef-DK project data from an unofficial Omnitruck API:
62
66
 
@@ -11,6 +11,8 @@ Feature: Metadata
11
11
  When I create a <Project> project
12
12
  Then the metadata has a url attribute
13
13
  And the metadata has a filename attribute
14
+ And the metadata has a version attribute
15
+ And the metadata has a build attribute
14
16
  And the metadata has an md5 attribute
15
17
  And the metadata has a sha256 attribute
16
18
  And the metadata doesn't have a yolo attribute
@@ -28,6 +30,8 @@ Feature: Metadata
28
30
  When I create a <Project> project
29
31
  Then the metadata has a url attribute
30
32
  And the metadata has a filename attribute
33
+ And the metadata has a version attribute
34
+ And the metadata has a build attribute
31
35
  And the metadata has an md5 attribute
32
36
  And the metadata has a sha256 attribute
33
37
  And the metadata has a yolo attribute
@@ -8,6 +8,10 @@ Then(/^the metadata (has|doesn't have) a(n)? (\w+) attribute$/) do |has, _, a|
8
8
  %r{^https://opscode-omnibus-packages\.s3\.amazonaws\.com.*$}
9
9
  when 'filename'
10
10
  /^[A-Za-z0-9_\.\-\+]+\.(rpm|deb|pkg|msi)$/
11
+ when 'version'
12
+ /^[A-Za-z0-9\.\+]+$/
13
+ when 'build'
14
+ /^[0-9]+$/
11
15
  when 'md5'
12
16
  /^\w{32}$/
13
17
  when 'sha256'
@@ -32,6 +32,7 @@ class Omnijack
32
32
  def initialize(name, args = {})
33
33
  super
34
34
  args.each { |k, v| send(k, v) unless v.nil? } unless args.nil?
35
+ to_h
35
36
  end
36
37
 
37
38
  #
@@ -41,6 +42,7 @@ class Omnijack
41
42
  define_method(a) { to_h[a] }
42
43
  end
43
44
  define_method(:filename) { to_h[:filename] }
45
+ define_method(:build) { to_h[:build] }
44
46
 
45
47
  #
46
48
  # Make metadata accessible via hash keys
@@ -60,13 +62,11 @@ class Omnijack
60
62
  def to_h
61
63
  raw_metadata.split("\n").each_with_object({}) do |line, hsh|
62
64
  key = line.split[0].to_sym
63
- val = case line.split[1]
64
- when 'true' then true
65
- when 'false' then false
66
- else line.split[1]
67
- end
65
+ val = line.split[1]
66
+ val = true if val == 'true'
67
+ val = false if val == 'false'
68
68
  hsh[key] = val
69
- hsh[:filename] = URI.decode(val).split('/')[-1] if key == :url
69
+ key == :url && hsh.merge!(parse_url_data(val)) && version(hsh[:version])
70
70
  end
71
71
  end
72
72
 
@@ -82,13 +82,7 @@ class Omnijack
82
82
  # @return [String]
83
83
  #
84
84
  def version(arg = nil)
85
- set_or_return(:version,
86
- arg,
87
- kind_of: String,
88
- default: 'latest',
89
- callbacks: {
90
- 'Invalid version string' => ->(a) { valid_version?(a) }
91
- })
85
+ set_or_return(:version, arg, kind_of: String, default: 'latest')
92
86
  end
93
87
 
94
88
  #
@@ -229,14 +223,16 @@ class Omnijack
229
223
  end
230
224
 
231
225
  #
232
- # Determine whether a string is a valid version string
226
+ # Extract a filename, package version, and build from a package URL
233
227
  #
234
- # @param [String] arg
235
- # @return [TrueClass, FalseClass]
228
+ # @param [String] url
229
+ # @return [[String] filename, [String] version, [String] build]
236
230
  #
237
- def valid_version?(arg)
238
- return true if arg == 'latest'
239
- arg.match(/^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$/) ? true : false
231
+ def parse_url_data(url)
232
+ filename = URI.decode(url).split('/')[-1]
233
+ { filename: filename,
234
+ version: filename.split('-')[-2].split('_')[-1],
235
+ build: filename.split('-')[-1].split('.')[0].split('_')[0] }
240
236
  end
241
237
  end
242
238
  end
@@ -20,5 +20,5 @@
20
20
  #
21
21
  # @author Jonathan Hartman <j@p4nt5.com>
22
22
  class Omnijack
23
- VERSION = '0.1.2'
23
+ VERSION = '0.2.0'
24
24
  end
@@ -25,7 +25,16 @@ describe Omnijack::Metadata do
25
25
  let(:args) { nil }
26
26
  let(:obj) { described_class.new(name, args) }
27
27
 
28
+ before(:each) do
29
+ allow_any_instance_of(described_class).to receive(:to_h).and_return(true)
30
+ end
31
+
28
32
  describe '#initialize' do
33
+ it 'initializes the object hash data' do
34
+ expect_any_instance_of(described_class).to receive(:to_h).and_return(true)
35
+ obj
36
+ end
37
+
29
38
  {
30
39
  platform: 'linspire',
31
40
  platform_version: '3.3.3',
@@ -50,7 +59,7 @@ describe Omnijack::Metadata do
50
59
  end
51
60
  end
52
61
 
53
- [:url, :md5, :sha256, :yolo, :filename].each do |i|
62
+ [:url, :md5, :sha256, :yolo, :filename, :build].each do |i|
54
63
  describe "##{i}" do
55
64
  before(:each) do
56
65
  allow_any_instance_of(described_class).to receive(:to_h)
@@ -64,7 +73,9 @@ describe Omnijack::Metadata do
64
73
  end
65
74
 
66
75
  describe '#[]' do
67
- let(:attributes) { [:url, :md5, :sha256, :yolo, :filename] }
76
+ let(:attributes) do
77
+ [:url, :md5, :sha256, :yolo, :filename, :version, :build]
78
+ end
68
79
 
69
80
  before(:each) do
70
81
  allow_any_instance_of(described_class).to receive(:to_h)
@@ -74,7 +85,7 @@ describe Omnijack::Metadata do
74
85
  end)
75
86
  end
76
87
 
77
- [:url, :md5, :sha256, :yolo, :filename].each do |a|
88
+ [:url, :md5, :sha256, :yolo, :filename, :version, :build].each do |a|
78
89
  it "returns the correct #{a}" do
79
90
  expect(obj[a]).to eq("#{a} things")
80
91
  end
@@ -82,7 +93,12 @@ describe Omnijack::Metadata do
82
93
  end
83
94
 
84
95
  describe '#to_h' do
85
- context 'fake data' do
96
+ before(:each) do
97
+ allow_any_instance_of(described_class).to receive(:to_h)
98
+ .and_call_original
99
+ end
100
+
101
+ context 'fake normal package data' do
86
102
  let(:url) do
87
103
  'https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/' \
88
104
  'chefdk-0.2.1-1.el6.x86_64.rpm'
@@ -103,10 +119,16 @@ describe Omnijack::Metadata do
103
119
 
104
120
  it 'returns the correct result hash' do
105
121
  expected = { url: url, md5: md5, sha256: sha256, yolo: yolo,
106
- filename: 'chefdk-0.2.1-1.el6.x86_64.rpm' }
122
+ filename: 'chefdk-0.2.1-1.el6.x86_64.rpm',
123
+ version: '0.2.1', build: '1' }
107
124
  expect(obj.to_h).to eq(expected)
108
125
  end
109
126
 
127
+ it 'overwrites the requested version with the actual package version' do
128
+ expect(obj.version).to eq('0.2.1')
129
+ expect(obj.instance_variable_get(:@version)).to eq('0.2.1')
130
+ end
131
+
110
132
  [true, false].each do |tf|
111
133
  context "data with a #{tf} value in it" do
112
134
  let(:yolo) { tf }
@@ -118,6 +140,35 @@ describe Omnijack::Metadata do
118
140
  end
119
141
  end
120
142
 
143
+ context 'fake nightly build data' do
144
+ let(:url) do
145
+ 'https://opscode-omnibus-packages.s3.amazonaws.com/mac_os_x/' \
146
+ '10.8/x86_64/chefdk-0.2.2%2B20140916163521.git.23.997cf31-1.dmg'
147
+ end
148
+ let(:md5) { 'e7f3ab946c851b50971d117bfa0f6e2c' }
149
+ let(:sha256) do
150
+ 'b9ecab8f2ebb258c3bdc341ab82310dfbfc8b8a5b27802481f27daf607ba7f99'
151
+ end
152
+ let(:yolo) { true }
153
+ let(:raw_metadata) do
154
+ "url\t#{url}\nmd5\t#{md5}\nsha256\t#{sha256}\nyolo\t#{yolo}"
155
+ end
156
+
157
+ before(:each) do
158
+ allow_any_instance_of(described_class).to receive(:raw_metadata)
159
+ .and_return(raw_metadata)
160
+ end
161
+
162
+ it 'decodes the encoded URL' do
163
+ expected = {
164
+ url: url, md5: md5, sha256: sha256, yolo: yolo,
165
+ filename: 'chefdk-0.2.2+20140916163521.git.23.997cf31-1.dmg',
166
+ version: '0.2.2+20140916163521.git.23.997cf31', build: '1'
167
+ }
168
+ expect(obj.to_h).to eq(expected)
169
+ end
170
+ end
171
+
121
172
  json = ::File.open(File.expand_path('../../support/real_test_data.json',
122
173
  __FILE__)).read
123
174
  JSON.parse(json, symbolize_names: true).each do |data|
@@ -131,6 +182,7 @@ describe Omnijack::Metadata do
131
182
  platform_version: data[:platform][:version],
132
183
  machine_arch: 'x86_64')
133
184
  end
185
+
134
186
  it 'returns the expected data' do
135
187
  if !data[:expected]
136
188
  expect { obj.to_h }.to raise_error(OpenURI::HTTPError)
@@ -541,36 +593,65 @@ describe Omnijack::Metadata do
541
593
  end
542
594
  end
543
595
 
544
- describe '#valid_version?' do
545
- context 'a "latest" version' do
546
- let(:res) { obj.send(:valid_version?, 'latest') }
596
+ describe '#parsed_url_data' do
597
+ let(:url) { nil }
598
+ let(:res) { obj.send(:parse_url_data, url) }
547
599
 
548
- it 'returns true' do
549
- expect(res).to eq(true)
600
+ context 'a standard RHEL package URL' do
601
+ let(:url) do
602
+ 'https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/' \
603
+ 'chefdk-0.2.1-1.el6.x86_64.rpm'
604
+ end
605
+
606
+ it 'extracts the right filename' do
607
+ expect(res[:filename]).to eq('chefdk-0.2.1-1.el6.x86_64.rpm')
550
608
  end
551
- end
552
609
 
553
- context 'a valid version' do
554
- let(:res) { obj.send(:valid_version?, '1.2.3') }
610
+ it 'extracts the right version' do
611
+ expect(res[:version]).to eq('0.2.1')
612
+ end
555
613
 
556
- it 'returns true' do
557
- expect(res).to eq(true)
614
+ it 'extracts the right build' do
615
+ expect(res[:build]).to eq('1')
558
616
  end
559
617
  end
560
618
 
561
- context 'a valid version + build' do
562
- let(:res) { obj.send(:valid_version?, '1.2.3-12') }
619
+ context 'a standard Ubuntu package URL' do
620
+ let(:url) do
621
+ 'https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/' \
622
+ 'x86_64/chefdk_0.2.1-1_amd64.deb'
623
+ end
624
+
625
+ it 'extracts the right filename' do
626
+ expect(res[:filename]).to eq('chefdk_0.2.1-1_amd64.deb')
627
+ end
563
628
 
564
- it 'returns true' do
565
- expect(res).to eq(true)
629
+ it 'extracts the right version' do
630
+ expect(res[:version]).to eq('0.2.1')
631
+ end
632
+
633
+ it 'extracts the right build' do
634
+ expect(res[:build]).to eq('1')
566
635
  end
567
636
  end
568
637
 
569
- context 'an invalid version' do
570
- let(:res) { obj.send(:valid_version?, 'x.y.z') }
638
+ context 'a nightly package URL' do
639
+ let(:url) do
640
+ 'https://opscode-omnibus-packages.s3.amazonaws.com/mac_os_x/' \
641
+ '10.8/x86_64/chefdk-0.2.2%2B20140916163521.git.23.997cf31-1.dmg'
642
+ end
643
+
644
+ it 'extracts the right filename' do
645
+ expected = 'chefdk-0.2.2+20140916163521.git.23.997cf31-1.dmg'
646
+ expect(res[:filename]).to eq(expected)
647
+ end
648
+
649
+ it 'extracts the right version' do
650
+ expect(res[:version]).to eq('0.2.2+20140916163521.git.23.997cf31')
651
+ end
571
652
 
572
- it 'returns false' do
573
- expect(res).to eq(false)
653
+ it 'extracts the right build' do
654
+ expect(res[:build]).to eq('1')
574
655
  end
575
656
  end
576
657
  end
@@ -33,6 +33,11 @@ describe Omnijack::Project do
33
33
  end
34
34
 
35
35
  describe '#metadata' do
36
+ before(:each) do
37
+ allow_any_instance_of(Omnijack::Metadata).to receive(:to_h)
38
+ .and_return(true)
39
+ end
40
+
36
41
  it 'returns a Metadata object' do
37
42
  res = obj
38
43
  [res.metadata, res.instance_variable_get(:@metadata)].each do |i|
@@ -7,6 +7,8 @@
7
7
  "expected": {
8
8
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.2-1_amd64.deb",
9
9
  "filename": "chefdk_0.2.2-1_amd64.deb",
10
+ "version": "0.2.2",
11
+ "build": "1",
10
12
  "md5": "1b097776840aa10f092063d1579bf155",
11
13
  "sha256": "a6384851473779d3b0d0bedc509607b924751ea3b356e7df4b9c7ab16dd25788"
12
14
  }
@@ -19,6 +21,8 @@
19
21
  "expected": {
20
22
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.1.0-1_amd64.deb",
21
23
  "filename": "chefdk_0.1.0-1_amd64.deb",
24
+ "version": "0.1.0",
25
+ "build": "1",
22
26
  "md5": "f7d53114f96e927261b4b2a2ecd3f232",
23
27
  "sha256": "0d66b93b62a24bd9c9735eefb4cd547bdf441f4a95effdfa068608c3821f85cb"
24
28
  }
@@ -36,10 +40,12 @@
36
40
  "prerelease": false,
37
41
  "nightlies": true,
38
42
  "expected": {
39
- "url": "https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.2%2B20140917085111.git.23.997cf31-1_amd64.deb",
40
- "filename": "chefdk_0.2.2+20140917085111.git.23.997cf31-1_amd64.deb",
41
- "md5": "03af55494419a3b3b32617fb76141ffc",
42
- "sha256": "e16c8d8cb594fe0fa82489d348af258f94e3e68ad8392bec31e3f12b5fd80285"
43
+ "url": "https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.2%2B20140918085104.git.23.997cf31-1_amd64.deb",
44
+ "filename": "chefdk_0.2.2+20140918085104.git.23.997cf31-1_amd64.deb",
45
+ "version": "0.2.2+20140918085104.git.23.997cf31",
46
+ "build": "1",
47
+ "md5": "424793c215d387041a9d620eeab1ed34",
48
+ "sha256": "801d36aa94aa452dbe81c05eb4422fb022e2e7cba3d35a67f02cfa7416ac628f"
43
49
  }
44
50
  },
45
51
  {
@@ -50,6 +56,8 @@
50
56
  "expected": {
51
57
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.2-1_amd64.deb",
52
58
  "filename": "chefdk_0.2.2-1_amd64.deb",
59
+ "version": "0.2.2",
60
+ "build": "1",
53
61
  "md5": "1b097776840aa10f092063d1579bf155",
54
62
  "sha256": "a6384851473779d3b0d0bedc509607b924751ea3b356e7df4b9c7ab16dd25788"
55
63
  }
@@ -62,6 +70,8 @@
62
70
  "expected": {
63
71
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/mac_os_x/10.8/x86_64/chefdk-0.2.2-1.dmg",
64
72
  "filename": "chefdk-0.2.2-1.dmg",
73
+ "version": "0.2.2",
74
+ "build": "1",
65
75
  "md5": "2d0d8881ef6b0cdcbaedfacac2d5129d",
66
76
  "sha256": "4922390a2dc08c26947fe8ed94a3a1777bd820e0e409e4072b2fb1315f4425d5"
67
77
  }
@@ -74,6 +84,8 @@
74
84
  "expected": {
75
85
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/mac_os_x/10.8/x86_64/chefdk-0.2.2-1.dmg",
76
86
  "filename": "chefdk-0.2.2-1.dmg",
87
+ "version": "0.2.2",
88
+ "build": "1",
77
89
  "md5": "2d0d8881ef6b0cdcbaedfacac2d5129d",
78
90
  "sha256": "4922390a2dc08c26947fe8ed94a3a1777bd820e0e409e4072b2fb1315f4425d5"
79
91
  }
@@ -86,6 +98,8 @@
86
98
  "expected": {
87
99
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chefdk-0.2.2-1.x86_64.rpm",
88
100
  "filename": "chefdk-0.2.2-1.x86_64.rpm",
101
+ "version": "0.2.2",
102
+ "build": "1",
89
103
  "md5": "5da3f329f7e6d51e778212dea4dae73f",
90
104
  "sha256": "2bc4c5c6f82ee7abed385d837e526fd40777ddc47ad939e4f3ecea625b43a245"
91
105
  }
@@ -98,6 +112,8 @@
98
112
  "expected": {
99
113
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chefdk-0.2.2-1.x86_64.rpm",
100
114
  "filename": "chefdk-0.2.2-1.x86_64.rpm",
115
+ "version": "0.2.2",
116
+ "build": "1",
101
117
  "md5": "5da3f329f7e6d51e778212dea4dae73f",
102
118
  "sha256": "2bc4c5c6f82ee7abed385d837e526fd40777ddc47ad939e4f3ecea625b43a245",
103
119
  "yolo": true
@@ -111,6 +127,8 @@
111
127
  "expected": {
112
128
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chefdk-0.2.2-1.msi",
113
129
  "filename": "chefdk-0.2.2-1.msi",
130
+ "version": "0.2.2",
131
+ "build": "1",
114
132
  "md5": "21f9af35451a0116b72531f06e93eb05",
115
133
  "sha256": "76038621bad5333b9ceee4dc32325cf2a880fa69ef64a9225d91ab1788c37a53"
116
134
  }
@@ -123,6 +141,8 @@
123
141
  "expected": {
124
142
  "url": "https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chefdk-0.2.2-1.msi",
125
143
  "filename": "chefdk-0.2.2-1.msi",
144
+ "version": "0.2.2",
145
+ "build": "1",
126
146
  "md5": "21f9af35451a0116b72531f06e93eb05",
127
147
  "sha256": "76038621bad5333b9ceee4dc32325cf2a880fa69ef64a9225d91ab1788c37a53",
128
148
  "yolo": true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnijack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Hartman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ohai