flirt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +67 -1
- data/flirt.gemspec +17 -15
- data/lib/flirt/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 034106def78faf22575247bb9ade0a9efe6fd2fc
|
4
|
+
data.tar.gz: 3c8de9cf124629172f5873d8608186cfec4a03dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d283374e38b19974d41218ac869a303d574144b32e2dcc3ec07466cb557e2c63856cc8c598096fca966a744cb00a077962836a1f2488ed399f5e6e1f95781bc
|
7
|
+
data.tar.gz: 90d7fe9305f4b7caea95d077a9be45b6141a10162e4ee3f75cb45bc38a0166ecc53629d16ff51e942e23b27b497da2e35297ae0663bc460113b0e713fc1fadcb
|
data/README.md
CHANGED
@@ -55,7 +55,6 @@ end
|
|
55
55
|
|
56
56
|
```ruby
|
57
57
|
Flirt.unsubscribe self, :picked, with: :picked_callback
|
58
|
-
end
|
59
58
|
```
|
60
59
|
|
61
60
|
|
@@ -149,6 +148,73 @@ Flirt.clear
|
|
149
148
|
|
150
149
|
This operation cannot be undone.
|
151
150
|
|
151
|
+
##Motivation
|
152
|
+
|
153
|
+
Ruby projects (and Rails projects in particular) can easily become a mess of tightly coupled code. The Rails framework almost encourages the idea of 'fat models', with features like callbacks (often touching other models and thus coupling themselves) and concerns (that use modules to hide code that often should really have its own class) to name but two.
|
154
|
+
|
155
|
+
The observer (or pub/sub) pattern can help decouple code, decompose large classes and allow for smaller classes with a single purpose. This promotes easy testing, readability, maintainability and eventually stability of your code.
|
156
|
+
|
157
|
+
So why another gem, considering there are already several gems and a Ruby language feature that implement this pattern?
|
158
|
+
|
159
|
+
### Flirt is tiny
|
160
|
+
|
161
|
+
Flirt gives you just enough to use and test the pub/sub pattern with the minimum of cruft. The number of objects is kept to a minimum for speed and ease of debugging. The extendable Listener module has only the two methods you need to use.
|
162
|
+
|
163
|
+
### Flirt use is obvious and readable
|
164
|
+
|
165
|
+
With such a simple syntax, it's easy to understand what Flirt is doing when you revisit your code again in three months.
|
166
|
+
|
167
|
+
### Flirt is opinionated
|
168
|
+
|
169
|
+
There is no set-up beyond requiring the gem.
|
170
|
+
|
171
|
+
Events are only allowed to be represented as symbols. Using strings or other objects will result in an exception, helping to spot and squash certain kinds of bugs early.
|
172
|
+
|
173
|
+
Only one object - Flirt - can be listened to, reducing the danger of implicit coupling between publishers and subscribers. Subscribers listen to events, not objects.
|
174
|
+
|
175
|
+
### Flirt has a great name
|
176
|
+
|
177
|
+
Seriously, why use any other gem when you could be flirting instead?
|
178
|
+
|
179
|
+
##Testing
|
180
|
+
|
181
|
+
In order to test units of behaviour, you probably want to disable Flirt and test each unit of your code in isolation. You can always enable Flirt or individual events in your test file for integration tests.
|
182
|
+
|
183
|
+
You'll want to clear Flirt before each test as well, to stop callbacks building up.
|
184
|
+
|
185
|
+
If you're using RSpec, you probably want to disable and clear Flirt in the before block in ```spec/spec_helper.rb```:
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
|
189
|
+
RSpec.configure do |config|
|
190
|
+
|
191
|
+
config.before(:each) do
|
192
|
+
Flirt.disable
|
193
|
+
Flirt.clear
|
194
|
+
end
|
195
|
+
...
|
196
|
+
```
|
197
|
+
|
198
|
+
If you're using MiniTest, something like this might help:
|
199
|
+
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
module FlirtMinitestPlugin
|
203
|
+
def before_setup
|
204
|
+
super
|
205
|
+
Flirt.disable
|
206
|
+
Flirt.clear
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
class MiniTest::Unit::TestCase
|
211
|
+
include FlirtMinitestPlugin
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
Another gem will probably appear soon to wrap common testing patterns around the use of Flirt. Watch this space.
|
216
|
+
|
217
|
+
|
152
218
|
## Contributing
|
153
219
|
|
154
220
|
1. Fork it ( https://github.com/[my-github-username]/flirt/fork )
|
data/flirt.gemspec
CHANGED
@@ -4,22 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'flirt/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
|
14
|
-
spec.
|
7
|
+
spec.name = "flirt"
|
8
|
+
spec.version = Flirt::VERSION
|
9
|
+
spec.authors = ["Benjamin Randles-Dunkley"]
|
10
|
+
spec.email = ["ben@chemica.co.uk"]
|
11
|
+
spec.summary = %q{ A brutally simple take on the observer pattern. }
|
12
|
+
spec.description = %q{ Provides a single point for the publication and subscription
|
13
|
+
of events, promoting extreme decoupling. }
|
14
|
+
spec.homepage = "https://github.com/chemica/flirt"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = '>= 1.9.2'
|
15
17
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files
|
19
|
-
spec.require_paths
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
20
22
|
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
-
spec.add_development_dependency "rake",
|
23
|
-
spec.add_development_dependency "rspec",
|
24
|
-
spec.add_development_dependency "byebug", "~> 4.0"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
26
|
+
# spec.add_development_dependency "byebug", "~> 4.0"
|
25
27
|
end
|
data/lib/flirt/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flirt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Randles-Dunkley
|
@@ -52,22 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
|
-
|
56
|
-
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '4.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '4.0'
|
69
|
-
description: " Provides a single point for the publication and subscription of events,
|
70
|
-
promoting extreme decoupling. "
|
55
|
+
description: " Provides a single point for the publication and subscription\n of
|
56
|
+
events, promoting extreme decoupling. "
|
71
57
|
email:
|
72
58
|
- ben@chemica.co.uk
|
73
59
|
executables: []
|
@@ -101,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
87
|
requirements:
|
102
88
|
- - ">="
|
103
89
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
90
|
+
version: 1.9.2
|
105
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
92
|
requirements:
|
107
93
|
- - ">="
|
@@ -109,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
95
|
version: '0'
|
110
96
|
requirements: []
|
111
97
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.4.1
|
113
99
|
signing_key:
|
114
100
|
specification_version: 4
|
115
101
|
summary: A brutally simple take on the observer pattern.
|