roda-container 0.0.4 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15d116dc716eb7e2220f95bab7a4179e53737569
4
- data.tar.gz: 02779f0dd1d9e5c7c6ab4bec115abd2f65d1d586
3
+ metadata.gz: 332f3de4a0b33b8ee1b9d15d0b4d2458321ad231
4
+ data.tar.gz: 49cfa204feae3922fd56f179fff187b1a5ec3f07
5
5
  SHA512:
6
- metadata.gz: 7134e5541427b5da8d8b49f217baccdc3d5063fe6a350ccbf19c09b68167821f97bdc5489d887c4ae032a0749f7c3b46b3d9bea9965dc85f62980cb7ebf6600d
7
- data.tar.gz: fcafa937f4f20c140ea30397a28478631381aad60f9a732e49af9e0d6260cbcc26d6568b82bdc344cb0edd9395027fd247dd7a0e1e8537601b83fa7123cb00d0
6
+ metadata.gz: f1d0773bec2dc4fe6e5ac3e36a81a4832afb24b78d1098d9be60f83986df68df89d45fe756689a44a62b8b4f9c3d3db718974002b598283f04be6d6c55836105
7
+ data.tar.gz: 3427710252525289662f4977db2024cc9d8ab83137167254e73d07f501c91918f7e6f3b4f6f61751a945b0f613b133cb82e8929e65c698cc8e81cac1172109bd
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # roda-container
1
+ # roda-container <a href="https://gitter.im/AMHOL/roda-container" target="_blank">![Join the chat at https://gitter.im/AMHOL/roda-container](https://badges.gitter.im/Join%20Chat.svg)</a>
2
2
 
3
3
  A plugin for Roda which turns your application into a (IoC) container
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```ruby
8
- gem 'roda-container', '0.0.3'
8
+ gem 'roda-container', '0.1.0'
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -47,13 +47,13 @@ MyApplication.route do |r|
47
47
  # Roda responds to the instance method #call, with the call: false
48
48
  # option, calling MyApplication.instance.resolve(:app) will not attempt to call
49
49
  # it, without the option, the application would error
50
- MyApplication.instance.register(:app, self, call: false)
50
+ register(:app, self, call: false) # Roda#register, regiser with the request container
51
51
  end
52
52
  ```
53
53
 
54
54
  ## Thread safety
55
55
 
56
- Please note the use of `MyApplication.instance.register` and `MyApplication.instance.resolve` above, without the calls to `Roda.instance` there is a high possiblilty of a thread safety issue when registering anything at runtime. For example:
56
+ Please note the use of and `MyApplication.instance.resolve` above, without the call to `Roda.instance` the item will not be present in the container, as it was registered with the request container (using Roda#register), without this, there is high possiblilty of a thread safety issue when registering anything at runtime. For example:
57
57
 
58
58
  ```ruby
59
59
  class MyApplication < Roda
@@ -62,7 +62,7 @@ end
62
62
 
63
63
  MyApplication.route do |r|
64
64
  # DO NOT DO THIS, SEE ABOVE ^^^
65
- MyApplication.register(:app, self, call: false)
65
+ MyApplication.register(:app, self, call: false) # Roda.register, register with the global container
66
66
 
67
67
  r.on 'users' do
68
68
  # ...
@@ -78,9 +78,17 @@ MyApplication.route do |r|
78
78
  end
79
79
  ```
80
80
 
81
- Immagine a user hitting `POST /users`, then another user hitting `GET /users/{id}` in quick succession; the first user registers their instance of app with the container, then hits the 5 second sleep, then the second user comes along, registers their instance of app with the container, the request executes and they go on their merry way.
81
+ Immagine a user hitting `POST /users`, then another user hitting `GET /users/{id}` in quick succession; the first user registers their instance of app with the global container, then hits the 5 second sleep, then the second user comes along, registers their instance of app with the global container, the request executes and they go on their merry way.
82
82
 
83
- A few seconds later the 5 second sleep is complete, and the first user resolves `:app` from the container, only to find the instance that was registered by the user hitting `GET /users/{id}`, they have just spent 5 minutes meticulously filling out your webform to create their user account, only for their payload to lost in a race condition, needless to say, you don't want this to happen.
83
+ A few seconds later the 5 second sleep is complete, and the first user resolves `:app` from the global container, only to find the application instance that was registered by the user hitting `GET /users/{id}`, they have just spent 5 minutes meticulously filling out your webform to create their user account, only for their payload to be lost in a race condition, needless to say - you don't want this to happen.
84
+
85
+ This is preventable by registering anything specific to a request with the request container, this is done using the `Roda#register` method, i.e.
86
+
87
+ ```ruby
88
+ MyApplication.route do |r|
89
+ register(:app, self, call: false) # Roda#register, regiser with the request container
90
+ end
91
+ ``
84
92
 
85
93
  ## Contributing
86
94
 
@@ -106,6 +106,10 @@ class Roda
106
106
  Thread.current[:__container__] = self.class.send(:container).dup
107
107
  super
108
108
  end
109
+
110
+ def register(*args, &block)
111
+ self.class.instance.register(*args, &block)
112
+ end
109
113
  end
110
114
  end
111
115
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler