pause 0.0.2 → 0.0.3

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.
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #^syntax detection
3
+
1
4
  source 'https://rubygems.org'
2
5
 
3
6
  # Specify your gem's dependencies in pause.gemspec
data/Guardfile CHANGED
@@ -6,8 +6,10 @@
6
6
 
7
7
  guard 'rspec' do
8
8
  watch(%r{^spanx\.gemspec}) { "spec"}
9
- watch(%r{^spec/.+_spec\.rb$})
10
9
  watch(%r{^lib/(.+)\.rb$}) { "spec" }
10
+
11
+ watch(%r{^spec/.+_spec\.rb$})
11
12
  watch('spec/spec_helper.rb') { "spec" }
13
+ watch(%r{spec/support/.*}) { "spec" }
12
14
  end
13
15
 
data/lib/pause/action.rb CHANGED
@@ -56,10 +56,12 @@ module Pause
56
56
  end
57
57
 
58
58
  def ok?
59
+ return true if self.class.disabled?
59
60
  Pause.analyzer.check(self).nil?
60
61
  end
61
62
 
62
63
  def analyze
64
+ return nil if self.class.disabled?
63
65
  Pause.analyzer.check(self)
64
66
  end
65
67
 
@@ -79,6 +81,33 @@ module Pause
79
81
  "#{self.scope}:#{@identifier}"
80
82
  end
81
83
 
84
+ # Actions can be globally disabled or re-enabled in a persistent
85
+ # way.
86
+ #
87
+ # MyAction.disable
88
+ # MyAction.enabled? => false
89
+ # MyAction.disabled? => true
90
+ #
91
+ # MyAction.enable
92
+ # MyAction.enabled? => true
93
+ # MyAction.disabled? => false
94
+ #
95
+ def self.enable
96
+ Pause.analyzer.adapter.enable(class_scope)
97
+ end
98
+
99
+ def self.disable
100
+ Pause.analyzer.adapter.disable(class_scope)
101
+ end
102
+
103
+ def self.enabled?
104
+ Pause.analyzer.adapter.enabled?(class_scope)
105
+ end
106
+
107
+ def self.disabled?
108
+ ! enabled?
109
+ end
110
+
82
111
  private
83
112
 
84
113
  def self.class_scope
@@ -54,6 +54,22 @@ module Pause
54
54
  redis.del (increment_keys + blocked_keys)
55
55
  end
56
56
 
57
+ def disable(scope)
58
+ redis.set("disabled:#{scope}", "1")
59
+ end
60
+
61
+ def enable(scope)
62
+ redis.del("disabled:#{scope}")
63
+ end
64
+
65
+ def disabled?(scope)
66
+ ! enabled?(scope)
67
+ end
68
+
69
+ def enabled?(scope)
70
+ redis.keys("disabled:#{scope}").first.nil?
71
+ end
72
+
57
73
  private
58
74
 
59
75
  def redis
data/lib/pause/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pause
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -47,14 +47,16 @@ describe Pause::Action do
47
47
  end
48
48
 
49
49
  it "should successfully consider different period checks" do
50
- time = Time.now
51
- Timecop.freeze time do
50
+ time = period_marker(resolution, Time.now.to_i + 1)
51
+
52
+ Timecop.freeze Time.at(time - 35) do
52
53
  4.times do
53
54
  action.increment!
54
55
  action.ok?.should be_true
55
56
  end
56
57
  end
57
- Timecop.freeze Time.at(time.to_i + 30) do
58
+
59
+ Timecop.freeze Time.at(time - 5) do
58
60
  2.times do
59
61
  action.increment!
60
62
  action.ok?.should be_true
@@ -63,6 +65,18 @@ describe Pause::Action do
63
65
  action.ok?.should be_false
64
66
  end
65
67
  end
68
+
69
+ context "action is disabled" do
70
+
71
+ it "should be true if action is disabled, even if blocked" do
72
+ 10.times { action.increment! }
73
+ action.ok?.should be_false
74
+
75
+ MyNotification.disable
76
+
77
+ action.ok?.should be_true
78
+ end
79
+ end
66
80
  end
67
81
 
68
82
  describe "#analyze" do
@@ -91,6 +105,17 @@ describe Pause::Action do
91
105
  blocked_action.timestamp.should == expected_blocked_action.timestamp
92
106
  end
93
107
  end
108
+
109
+ context "action is disabled" do
110
+ it "return nil, even if blocked" do
111
+ 10.times { action.increment! }
112
+ action.should_not be_ok
113
+
114
+ MyNotification.disable
115
+
116
+ action.analyze.should be_nil
117
+ end
118
+ end
94
119
  end
95
120
 
96
121
  describe "#tracked_identifiers" do
@@ -183,3 +208,45 @@ describe Pause::Action, ".scope" do
183
208
  DefinedScopeAction.new("1.2.3.4").scope.should == "my:scope"
184
209
  end
185
210
  end
211
+
212
+ describe Pause::Action, "enabled/disabled states" do
213
+ class BlockedAction < Pause::Action
214
+ scope "blocked"
215
+ check 10, 0, 10
216
+ end
217
+
218
+ before do
219
+ Pause.configure do |c|
220
+ c.resolution = 10
221
+ c.history = 10
222
+ end
223
+ end
224
+
225
+ let(:action) { BlockedAction }
226
+
227
+ describe "#disable" do
228
+ before do
229
+ action.should be_enabled
230
+ action.should_not be_disabled
231
+ action.disable
232
+ end
233
+
234
+ it "disables the action" do
235
+ action.should be_disabled
236
+ action.should_not be_enabled
237
+ end
238
+ end
239
+
240
+ describe "#enable" do
241
+ before do
242
+ action.disable
243
+ action.should_not be_enabled
244
+ action.enable
245
+ end
246
+
247
+ it "enables the action" do
248
+ action.should be_enabled
249
+ action.should_not be_disabled
250
+ end
251
+ end
252
+ end
@@ -1 +1,3 @@
1
+ require 'fakeredis'
1
2
  require 'fakeredis/rspec'
3
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pause
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: