jsmestad-stale_fish 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/stale_fish.rb +31 -51
- data/spec/stale_fish_spec.rb +8 -0
- data/stale_fish.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/stale_fish.rb
CHANGED
@@ -12,56 +12,51 @@ end
|
|
12
12
|
|
13
13
|
module StaleFish
|
14
14
|
# no one likes stale fish.
|
15
|
-
def self.use_fakeweb=(enabled)
|
16
|
-
@use_fakeweb = enabled
|
17
|
-
end
|
18
15
|
|
19
|
-
|
20
|
-
|
16
|
+
class << self
|
17
|
+
attr_accessor :use_fakeweb
|
18
|
+
attr_accessor :config_path
|
19
|
+
attr_accessor :yaml
|
20
|
+
attr_accessor :configuration
|
21
21
|
end
|
22
22
|
|
23
23
|
self.use_fakeweb = false
|
24
24
|
|
25
|
-
def self.config_path=(path)
|
26
|
-
@config_path = path
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.config_path
|
30
|
-
@config_path
|
31
|
-
end
|
32
|
-
|
33
25
|
def self.valid_path?
|
34
|
-
return false if
|
35
|
-
File.exist?(
|
26
|
+
return false if config_path.nil?
|
27
|
+
File.exist?(config_path)
|
36
28
|
end
|
37
29
|
|
38
30
|
def self.update_stale(*args)
|
39
31
|
# check each file for update
|
40
|
-
load_yaml if self.yaml.nil?
|
32
|
+
load_yaml #if self.yaml.nil?
|
41
33
|
stale = flag_stale(args)
|
42
34
|
process(stale)
|
43
35
|
write_yaml
|
44
36
|
return stale.size
|
45
37
|
end
|
46
38
|
|
47
|
-
def self.yaml=(data)
|
48
|
-
@yaml = data
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.yaml
|
52
|
-
!@yaml.nil? ? @yaml['stale'] : @yaml
|
53
|
-
end
|
54
|
-
|
55
39
|
def self.register_uri(source_uri, response)
|
56
|
-
if
|
40
|
+
if use_fakeweb && !FakeWeb.registered_uri?(source_uri)
|
57
41
|
FakeWeb.register_uri(:any, source_uri, :body => response)
|
58
42
|
end
|
59
43
|
end
|
60
44
|
|
61
45
|
def self.load_yaml
|
62
46
|
if valid_path?
|
63
|
-
|
64
|
-
|
47
|
+
self.yaml = YAML.load_file(config_path)
|
48
|
+
raise YAML::Error, 'missing stale root element' unless self.yaml['stale']
|
49
|
+
|
50
|
+
# Grab Configuration from YAML
|
51
|
+
configuration = self.yaml['stale'].delete('configuration')
|
52
|
+
use_fakeweb = (@configuration['use_fakeweb'] || false) unless configuration.nil?
|
53
|
+
|
54
|
+
# Process remaining nodes as items
|
55
|
+
self.yaml['stale'].each do |key, value|
|
56
|
+
%w{ filepath frequency source }.each do |field|
|
57
|
+
raise YAML::Error, "missing #{field} node for #{key}" unless self.yaml['stale'][key][field]
|
58
|
+
end
|
59
|
+
end
|
65
60
|
else
|
66
61
|
raise Errno::ENOENT, 'invalid path, please set StaleFish.config_path than ensure StaleFish.valid_path? is true'
|
67
62
|
end
|
@@ -69,24 +64,9 @@ module StaleFish
|
|
69
64
|
|
70
65
|
protected
|
71
66
|
|
72
|
-
def self.check_syntax
|
73
|
-
raise YAML::Error, 'missing stale root element' unless @yaml['stale']
|
74
|
-
|
75
|
-
# Grab Configuration from YAML
|
76
|
-
@configuration = @yaml['stale'].delete('configuration')
|
77
|
-
self.use_fakeweb = (@configuration['use_fakeweb'] || false) unless @configuration.nil?
|
78
|
-
|
79
|
-
# Process remaining nodes as items
|
80
|
-
@yaml['stale'].each do |key, value|
|
81
|
-
%w{ filepath frequency source }.each do |field|
|
82
|
-
raise YAML::Error, "missing #{field} node for #{key}" unless @yaml['stale'][key][field]
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
67
|
def self.flag_stale(args)
|
88
68
|
force = args.pop[:force] if args.last.is_a?(Hash)
|
89
|
-
stale, scope = {}, self.yaml
|
69
|
+
stale, scope = {}, self.yaml['stale']
|
90
70
|
scope.each do |key, value|
|
91
71
|
if args.empty?
|
92
72
|
if scope[key]['updated'].blank?
|
@@ -97,7 +77,7 @@ protected
|
|
97
77
|
if last_modified > update_on
|
98
78
|
stale.merge!({key => scope[key]})
|
99
79
|
else
|
100
|
-
|
80
|
+
register_uri(scope[key]['source'], scope[key]['filepath'])
|
101
81
|
end
|
102
82
|
end
|
103
83
|
else
|
@@ -109,7 +89,7 @@ protected
|
|
109
89
|
if args.include?(key) && (scope[key]['updated'].blank? || last_modified > update_on)
|
110
90
|
stale.merge!({key => scope[key]})
|
111
91
|
else
|
112
|
-
|
92
|
+
register_uri(scope[key]['source'], scope[key]['filepath'])
|
113
93
|
end
|
114
94
|
end
|
115
95
|
end
|
@@ -118,24 +98,24 @@ protected
|
|
118
98
|
end
|
119
99
|
|
120
100
|
def self.process(fixtures)
|
121
|
-
FakeWeb.allow_net_connect = true if
|
101
|
+
FakeWeb.allow_net_connect = true if use_fakeweb
|
122
102
|
|
123
103
|
fixtures.each do |key, value|
|
124
104
|
rio(fixtures[key]['source']) > rio(fixtures[key]['filepath'])
|
125
|
-
|
105
|
+
register_uri(fixtures[key]['source'], fixtures[key]['filepath'])
|
126
106
|
update_fixture(key)
|
127
107
|
end
|
128
108
|
|
129
|
-
FakeWeb.allow_net_connect = false if
|
109
|
+
FakeWeb.allow_net_connect = false if use_fakeweb
|
130
110
|
end
|
131
111
|
|
132
112
|
def self.update_fixture(key)
|
133
|
-
|
113
|
+
self.yaml['stale'][key]['updated'] = DateTime.now
|
134
114
|
end
|
135
115
|
|
136
116
|
def self.write_yaml
|
137
|
-
File.open(
|
138
|
-
f.write(
|
117
|
+
File.open(config_path, "w+") do |f|
|
118
|
+
f.write(self.yaml.to_yaml)
|
139
119
|
end
|
140
120
|
end
|
141
121
|
|
data/spec/stale_fish_spec.rb
CHANGED
@@ -46,6 +46,14 @@ describe "StaleFish" do
|
|
46
46
|
StaleFish.update_stale('google', :force => true).should == 1
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should not have any remaining fixtures to update" do
|
50
|
+
StaleFish.update_stale.should == 2
|
51
|
+
StaleFish.yaml = nil # this will force a reload of the YAML file.
|
52
|
+
StaleFish.yaml.should == nil # ensure it was reset
|
53
|
+
StaleFish.load_yaml
|
54
|
+
StaleFish.update_stale.should == 0
|
55
|
+
end
|
56
|
+
|
49
57
|
it "should notify user, and rollback, if source is no longer valid"
|
50
58
|
|
51
59
|
after(:each) do
|
data/stale_fish.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stale_fish}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Smestad"]
|
12
|
-
s.date = %q{2009-09-
|
12
|
+
s.date = %q{2009-09-15}
|
13
13
|
s.email = %q{justin.smestad@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsmestad-stale_fish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Smestad
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-15 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|