das_catalog 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/das_catalog/screencast_data.rb +8 -1
- data/lib/das_catalog/store.rb +35 -9
- data/lib/das_catalog/version.rb +1 -1
- data/spec/das_screencast_data_spec.rb +5 -0
- data/spec/das_store_spec.rb +27 -1
- metadata +14 -14
@@ -1,9 +1,16 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module DasCatalog
|
2
4
|
class ScreencastData
|
3
|
-
attr_reader :link, :watched, :downloaded
|
5
|
+
attr_reader :link, :watched, :downloaded, :uuid
|
4
6
|
|
5
7
|
def initialize(link)
|
6
8
|
@link = link
|
9
|
+
initialize_uuid
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize_uuid
|
13
|
+
@uuid ||= SecureRandom.uuid
|
7
14
|
end
|
8
15
|
|
9
16
|
def self.for_link(link)
|
data/lib/das_catalog/store.rb
CHANGED
@@ -1,18 +1,44 @@
|
|
1
1
|
require 'pstore'
|
2
2
|
|
3
3
|
module DasCatalog
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Store
|
5
|
+
class UUIDMismatch < StandardError; end
|
6
|
+
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def pstore
|
10
|
+
@pstore ||= PStore.new(DasCatalog.tracker_file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset
|
14
|
+
pstore.transaction do
|
15
|
+
pstore.roots.each do |key|
|
16
|
+
pstore.delete key
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def find(id)
|
22
|
+
pstore.transaction(true) do
|
23
|
+
pstore[id]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def all
|
28
|
+
pstore.transaction(true) do
|
29
|
+
pstore.roots.collect do |name|
|
30
|
+
pstore[name]
|
31
|
+
end
|
9
32
|
end
|
10
33
|
end
|
11
34
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
35
|
+
def store(screencast_data)
|
36
|
+
if sd = find(screencast_data.id)
|
37
|
+
raise UUIDMismatch if sd.uuid && sd.uuid != screencast_data.uuid
|
38
|
+
end
|
39
|
+
|
40
|
+
pstore.transaction do
|
41
|
+
pstore[screencast_data.id] = screencast_data
|
16
42
|
end
|
17
43
|
end
|
18
44
|
end
|
data/lib/das_catalog/version.rb
CHANGED
@@ -8,6 +8,11 @@ describe DasCatalog::ScreencastData do
|
|
8
8
|
subject.download_link.must_equal("#{link}/download")
|
9
9
|
end
|
10
10
|
|
11
|
+
it "assigns a uuid using SecureRandom.uuid" do
|
12
|
+
SecureRandom.stubs(:uuid).returns("spec-uuid")
|
13
|
+
subject.uuid.must_equal "spec-uuid"
|
14
|
+
end
|
15
|
+
|
11
16
|
it "uses the link as the id" do
|
12
17
|
subject.id.must_equal link
|
13
18
|
end
|
data/spec/das_store_spec.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
require_relative "spec_helper"
|
2
2
|
|
3
|
+
require 'securerandom'
|
4
|
+
|
3
5
|
describe DasCatalog::Store do
|
4
6
|
let(:link) { "https://www.destroyallsoftware.com/screencasts/catalog/statistics-over-git-repositories" }
|
5
7
|
let(:id) { link }
|
6
|
-
let(:screencast_data)
|
8
|
+
let(:screencast_data) do
|
9
|
+
scd = mock();
|
10
|
+
scd.stubs(:id).returns(id);
|
11
|
+
scd.stubs(:uuid).returns(SecureRandom.uuid)
|
12
|
+
scd
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
DasCatalog::Store.reset
|
17
|
+
end
|
7
18
|
|
8
19
|
it "tracks in the file specified in config" do
|
9
20
|
DasCatalog::Store.store(screencast_data)
|
@@ -18,4 +29,19 @@ describe DasCatalog::Store do
|
|
18
29
|
it "is nil if the screencast is not found" do
|
19
30
|
refute DasCatalog::Store.find(id)
|
20
31
|
end
|
32
|
+
|
33
|
+
it "can reset the store to be empty" do
|
34
|
+
DasCatalog::Store.store(screencast_data)
|
35
|
+
assert DasCatalog::Store.find(screencast_data.id)
|
36
|
+
DasCatalog::Store.reset
|
37
|
+
refute DasCatalog::Store.find(screencast_data.id)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "raises an exeption trying to store screencast data if one exists with a different uuid" do
|
41
|
+
DasCatalog::Store.store(screencast_data)
|
42
|
+
screencast_data.stubs(:uuid).returns(SecureRandom.uuid)
|
43
|
+
proc {
|
44
|
+
DasCatalog::Store.store(screencast_data)
|
45
|
+
}.must_raise(DasCatalog::Store::UUIDMismatch)
|
46
|
+
end
|
21
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: das_catalog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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: 2011-12-
|
12
|
+
date: 2011-12-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: feedzirra
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160743580 !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: *2160743580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mechanize
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160742560 !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: *2160742560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: highline
|
38
|
-
requirement: &
|
38
|
+
requirement: &2160742100 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160742100
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: minitest
|
49
|
-
requirement: &
|
49
|
+
requirement: &2160741680 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2160741680
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &2160741120 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2160741120
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fakefs
|
71
|
-
requirement: &
|
71
|
+
requirement: &2160733860 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2160733860
|
80
80
|
description: Download screencasts from Destroy All Software catalog. Uses the rss
|
81
81
|
feed plus Mechanize to log you in and then download new movies to your local drive.
|
82
82
|
email: xternal1+github@gmail.com
|