idregistry 0.1.1 → 0.1.2

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.
@@ -1,3 +1,7 @@
1
+ === 0.1.2 / 2012-08-03
2
+
3
+ * Added :before_request option to ClearRegistry middleware task.
4
+
1
5
  === 0.1.1 / 2012-08-01
2
6
 
3
7
  * Forgot to declare blockenspiel as a gem dependency. Fixed.
data/Version CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -260,10 +260,6 @@ module IDRegistry
260
260
  # Add a simple pattern, using the given proc to generate objects
261
261
  # matching that pattern.
262
262
  #
263
- # [<tt>add_pattern( <i>pattern</i>, <i>to_generate_object</i>, <i>to_generate_tuple</i> )</tt>]
264
- # Add a simple pattern, using the given proc to generate objects
265
- # matching that pattern, and to generate a tuple from an object.
266
- #
267
263
  # [<tt>add_pattern( <i>pattern</i>, <i>type</i>, <i>to_generate_object</i>, <i>to_generate_tuple</i> )</tt>]
268
264
  # Add a pattern for the given type. You should provide both a proc
269
265
  # to generate objects, and a proc to generate a tuple from an object.
@@ -61,19 +61,25 @@ module IDRegistry
61
61
 
62
62
  # Create a new ClearRegistry task. You must provide the registry
63
63
  # and an optional condition block.
64
- def initialize(registry_, &condition_)
64
+ # If you set the <tt>:before_request</tt> option to true, the
65
+ # registry clearing will take place at the beginning of the request
66
+ # rather than the end.
67
+ def initialize(registry_, opts_={}, &condition_)
65
68
  @condition = condition_
66
69
  @registry = registry_
70
+ @before = opts_[:before_request]
67
71
  end
68
72
 
69
- # The pre method for this task does nothing.
73
+ # The pre method applies if <tt>:before_request</tt> is set.
70
74
  def pre(env_)
75
+ if @before && (!@condition || @condition.call(env_))
76
+ @registry.clear
77
+ end
71
78
  end
72
79
 
73
- # The post method for this task clears the registry if the
74
- # condition block passes
80
+ # The pre method applies if <tt>:before_request</tt> is not set.
75
81
  def post(env_)
76
- if !@condition || @condition.call(env_)
82
+ if !@before && (!@condition || @condition.call(env_))
77
83
  @registry.clear
78
84
  end
79
85
  end
@@ -64,7 +64,7 @@ module IDRegistry
64
64
 
65
65
  def initialize # :nodoc:
66
66
  @tasks = []
67
- @after_middleware = nil
67
+ @before_middleware = nil
68
68
  end
69
69
 
70
70
 
@@ -82,9 +82,13 @@ module IDRegistry
82
82
  # Rack environment. The registry is cleared only if the block
83
83
  # returns a true value. If no block is provided, the registry is
84
84
  # always cleared at the end of a request.
85
+ #
86
+ # If you set the <tt>:before_request</tt> option to true, the
87
+ # registry clearing will take place at the beginning of the request
88
+ # rather than the end.
85
89
 
86
- def clear_registry(reg_, &condition_)
87
- @tasks << RegistryMiddleware::ClearRegistry.new(reg_, &condition_)
90
+ def clear_registry(reg_, opts_={}, &condition_)
91
+ @tasks << RegistryMiddleware::ClearRegistry.new(reg_, opts_, &condition_)
88
92
  self
89
93
  end
90
94
 
@@ -77,6 +77,7 @@ module IDRegistry
77
77
  @registry.lookup(:hello, 1)
78
78
  assert_equal(1, @registry.size)
79
79
  task_.pre({})
80
+ assert_equal(1, @registry.size)
80
81
  task_.post({})
81
82
  assert_equal(0, @registry.size)
82
83
  end
@@ -97,6 +98,17 @@ module IDRegistry
97
98
  end
98
99
 
99
100
 
101
+ def test_clear_registry_task_before_request
102
+ task_ = RegistryMiddleware::ClearRegistry.new(@registry, :before_request => true)
103
+ @registry.lookup(:hello, 1)
104
+ assert_equal(1, @registry.size)
105
+ task_.pre({})
106
+ assert_equal(0, @registry.size)
107
+ task_.post({})
108
+ assert_equal(0, @registry.size)
109
+ end
110
+
111
+
100
112
  def test_spawn_registry_task
101
113
  task_ = RegistryMiddleware::SpawnRegistry.new(@registry.config.lock, :reg)
102
114
  obj1_ = @registry.lookup(:hello, 1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idregistry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blockenspiel