chicanery 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chicanery (0.0.6)
4
+ chicanery (0.0.7)
5
5
  nokogiri (~> 1)
6
6
 
7
7
  GEM
@@ -16,35 +16,47 @@ module Chicanery
16
16
  include Handlers
17
17
  include StateComparison
18
18
 
19
- VERSION = "0.0.6"
19
+ VERSION = "0.0.7"
20
20
 
21
21
  def execute args
22
+ load args.shift
23
+ poll_period = args.shift
24
+ if poll_period
25
+ run_every poll_period.to_i
26
+ else
27
+ run
28
+ end
29
+ end
30
+
31
+ def run_every poll_period
22
32
  begin
23
- load args.shift
24
- poll_period = args.shift
25
33
  loop do
26
- previous_state = restore
27
- current_state = {
28
- servers: {},
29
- repos: {}
30
- }
31
- repos.each do |repo|
32
- repo_state = repo.state
33
- compare_repo_state repo.name, repo_state, previous_state[:repos][repo.name] if previous_state[:repos]
34
- current_state[:repos][repo.name] = repo_state
35
- end
36
- servers.each do |server|
37
- current_jobs = server.jobs
38
- compare_jobs current_jobs, previous_state[:servers][server.name] if previous_state[:servers]
39
- current_state[:servers][server.name] = current_jobs
40
- end
41
- current_state.extend Chicanery::Summary
42
- run_handlers.each {|handler| handler.call current_state }
43
- persist current_state
44
- break unless poll_period
45
- sleep poll_period.to_i
34
+ run
35
+ sleep poll_period
46
36
  end
47
37
  rescue Interrupt
48
38
  end
49
39
  end
40
+
41
+ def run
42
+ previous_state = restore
43
+ current_state = {
44
+ servers: {},
45
+ repos: {}
46
+ }
47
+ repos.each do |repo|
48
+ repo_state = repo.state
49
+ compare_repo_state repo.name, repo_state, previous_state[:repos][repo.name] if previous_state[:repos]
50
+ current_state[:repos][repo.name] = repo_state
51
+ end
52
+ servers.each do |server|
53
+ current_jobs = server.jobs
54
+ compare_jobs current_jobs, previous_state[:servers][server.name] if previous_state[:servers]
55
+ current_state[:servers][server.name] = current_jobs
56
+ end
57
+ current_state.extend Chicanery::Summary
58
+ run_handlers.each {|handler| handler.call current_state }
59
+ persist current_state
60
+ end
61
+
50
62
  end
@@ -27,4 +27,4 @@ describe Chicanery do
27
27
  execute %w{configuration 10}
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -0,0 +1,49 @@
1
+ describe Chicanery do
2
+ include Chicanery
3
+
4
+ describe '#run' do
5
+
6
+ before do
7
+ server double("Server A", :name => "A", :jobs => "A jobs")
8
+ server double("Server B", :name => "B", :jobs => "B jobs")
9
+ repo double("repo X", :name => "X", :state => "X state")
10
+ repo double("repo Y", :name => "Y", :state => "Y state")
11
+ when_run do |current_state|
12
+ @current_state = current_state
13
+ end
14
+ @current_state = nil
15
+ end
16
+
17
+ before { stub!("restore").and_return({})}
18
+ before { %w{persist}.each {|m| stub! m } }
19
+
20
+ it "notifies when_run listeners of the current state of the servers jobs" do
21
+ run
22
+ @current_state[:servers]["A"].should == "A jobs"
23
+ @current_state[:servers]["B"].should == "B jobs"
24
+ end
25
+
26
+ it "notifies when_run listeners of the current state of the repos" do
27
+ run
28
+ @current_state[:repos]["X"].should == "X state"
29
+ @current_state[:repos]["Y"].should == "Y state"
30
+ end
31
+
32
+ #TESTS TODO
33
+ # it restores previous state and records current state
34
+ # it compares current state and previous state for each server
35
+ # it compares current state and previous state for each server
36
+
37
+ end
38
+
39
+ describe '#run_every' do
40
+ it "polls with a specified period" do
41
+ should_receive(:run).exactly(3).times
42
+ should_receive(:sleep).with(10).ordered
43
+ should_receive(:sleep).with(10).ordered
44
+ should_receive(:sleep).with(10).ordered.and_raise Interrupt
45
+ run_every 10
46
+ end
47
+ end
48
+
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chicanery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-13 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -123,6 +123,7 @@ files:
123
123
  - spec/chicanery/state_comparison_spec.rb
124
124
  - spec/chicanery/summary_spec.rb
125
125
  - spec/chicanery_spec.rb
126
+ - spec/embedded_chicanery_spec.rb
126
127
  homepage: http://github.com/markryall/chicanery
127
128
  licenses: []
128
129
  post_install_message:
@@ -137,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
138
  version: '0'
138
139
  segments:
139
140
  - 0
140
- hash: -1603803825861310736
141
+ hash: 3593176938821015770
141
142
  required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  none: false
143
144
  requirements:
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  version: '0'
147
148
  segments:
148
149
  - 0
149
- hash: -1603803825861310736
150
+ hash: 3593176938821015770
150
151
  requirements: []
151
152
  rubyforge_project:
152
153
  rubygems_version: 1.8.23
@@ -159,3 +160,4 @@ test_files:
159
160
  - spec/chicanery/state_comparison_spec.rb
160
161
  - spec/chicanery/summary_spec.rb
161
162
  - spec/chicanery_spec.rb
163
+ - spec/embedded_chicanery_spec.rb