stale_fish 1.3.0.pre2 → 1.3.0.pre3
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/fixture.rb +28 -5
- data/spec/unit/fixture_spec.rb +7 -1
- data/stale_fish.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.0.
|
1
|
+
1.3.0.pre3
|
data/lib/stale_fish/fixture.rb
CHANGED
@@ -3,7 +3,9 @@ require 'activesupport'
|
|
3
3
|
module StaleFish
|
4
4
|
class Fixture
|
5
5
|
attr_accessor :name, :file, :last_updated_at
|
6
|
-
attr_accessor :update_interval
|
6
|
+
attr_accessor :update_interval
|
7
|
+
attr_accessor :check_against, :request_type
|
8
|
+
attr_accessor :update_method
|
7
9
|
|
8
10
|
def initialize(attributes={})
|
9
11
|
attributes.each do |key, value|
|
@@ -20,6 +22,20 @@ module StaleFish
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def update!
|
25
|
+
response = if update_method
|
26
|
+
update_by_method
|
27
|
+
else
|
28
|
+
update_by_network
|
29
|
+
end
|
30
|
+
write_response_to_file(response)
|
31
|
+
self.last_updated_at = DateTime.now
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_by_method
|
35
|
+
return eval(update_method)
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_by_network
|
23
39
|
uri, type = URI.parse(check_against), request_type.downcase.to_sym
|
24
40
|
Net::HTTP.start(uri.host) do |http|
|
25
41
|
response = if type == :post
|
@@ -27,10 +43,8 @@ module StaleFish
|
|
27
43
|
else
|
28
44
|
http.get(uri.path)
|
29
45
|
end
|
30
|
-
|
46
|
+
return response.body
|
31
47
|
end
|
32
|
-
|
33
|
-
self.last_updated_at = DateTime.now
|
34
48
|
end
|
35
49
|
|
36
50
|
def register_lock!
|
@@ -42,12 +56,21 @@ module StaleFish
|
|
42
56
|
|
43
57
|
def to_yaml
|
44
58
|
# update_interval.inspect trick is to prevent Fixnum being written
|
45
|
-
yaml =
|
59
|
+
yaml = ""
|
60
|
+
yaml << <<-EOF
|
46
61
|
#{name}:
|
47
62
|
file: '#{file}'
|
48
63
|
update_interval: #{update_interval.inspect.gsub(/ /, '.').gsub(/"/, '')}
|
49
64
|
check_against: #{check_against}
|
50
65
|
request_type: #{request_type}
|
66
|
+
EOF
|
67
|
+
if update_method
|
68
|
+
yaml << <<-EOF
|
69
|
+
update_method: #{update_method}
|
70
|
+
EOF
|
71
|
+
end
|
72
|
+
|
73
|
+
yaml << <<-EOF
|
51
74
|
last_updated_at: #{last_updated_at}
|
52
75
|
EOF
|
53
76
|
return yaml
|
data/spec/unit/fixture_spec.rb
CHANGED
@@ -58,7 +58,13 @@ describe StaleFish::Fixture do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should use Net::HTTP#get with a GET request_type"
|
61
|
-
|
61
|
+
|
62
|
+
it "should call update_method when present" do
|
63
|
+
@fixture.update_method = "CONSTANT"
|
64
|
+
@fixture.should_receive(:update_by_method).once
|
65
|
+
@fixture.update!
|
66
|
+
|
67
|
+
end
|
62
68
|
end
|
63
69
|
|
64
70
|
context "#register_lock!" 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.3.0.
|
8
|
+
s.version = "1.3.0.pre3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Smestad"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-23}
|
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: stale_fish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.0.
|
4
|
+
version: 1.3.0.pre3
|
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: 2010-02-
|
12
|
+
date: 2010-02-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|