ducktape 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8a085735246f605392018ae227b1ff561bb2a12
4
- data.tar.gz: 2d3baf29ccdb08ac0728b3cf34b5e602a7cb6e94
3
+ metadata.gz: dc41d10e9abd72c09e3cafefeaef59e8fc37a6c8
4
+ data.tar.gz: 802765ccaa3a370f4dc230b9289dcfea395f80c7
5
5
  SHA512:
6
- metadata.gz: 1c74d85e393cf8a48fcf2f3596f4cca53f4c0d3d35fdb948a1117037080db06f429133f2b5241f95ae1736b74a0282a5221ec0c43a3183a1a8418e4509c90577
7
- data.tar.gz: 65367871b957ae760debacf750b2b3702c56dc7432b521d91efc4ad606e9f68c931ce59745ceccad3430ab0dd31f55ba94b9887d76c110c7ef28a032adec3d45
6
+ metadata.gz: 5a543866fbc7e14ead0ed1495dba9a62be405afbeb9f70adaad9a0180b44d11e46c492142bfdeedaeae0bb347b559bbf408fb867030902969fb623745b114e49
7
+ data.tar.gz: 796f8e6a44c1830533f42dca20cd14e007d7fd9625a41aad81c60a61606638cb91c1ba575d8bc1e749d34598ce5c5b73ad9aecb8496cebebaa28d5f3072b9bfa
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ## DESCRIPTION:
12
12
 
13
- A [truly outrageous](http://youtu.be/dSPb56-_I98) gem for bindable attributes and event notification.
13
+ A [truly outrageous](https://youtu.be/lkQE5wuBFeY8) gem for bindable attributes and event notification.
14
14
 
15
15
  ## SYNOPSIS:
16
16
 
@@ -39,4 +39,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
39
39
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
40
40
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41
41
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,7 +1,7 @@
1
1
  module Ducktape
2
2
  class BindableAttributeMetadata
3
3
 
4
- @validators = [ ClassValidator, ProcValidator, RegexpValidator, RangeValidator ]
4
+ @validators = [ ClassValidator, ProcValidator, RegexpValidator, RangeValidator, EqualityValidator ]
5
5
 
6
6
  VALID_OPTIONS = [:access, :coerce, :default, :getter, :setter, :validate].freeze
7
7
 
@@ -86,7 +86,7 @@ module Ducktape
86
86
  end
87
87
 
88
88
  def self.create_validator(validator)
89
- validator_class = @validators.find { |validator_class| validator_class.matches?(validator) } || EqualityValidator
89
+ validator_class = @validators.find { |validator_class| validator_class.matches?(validator) }
90
90
  validator_class.new(validator)
91
91
  end
92
92
 
@@ -3,11 +3,7 @@ module Ducktape
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
5
 
6
- if base.is_a?(Class)
7
- base.include InstanceMethods
8
- base.def_hook(:on_changed) unless base.method_defined?(:on_changed)
9
- return
10
- end
6
+ return if base.is_a?(Class)
11
7
 
12
8
  # Module
13
9
 
@@ -103,97 +99,99 @@ module Ducktape
103
99
  end
104
100
  end
105
101
 
106
- module InstanceMethods
102
+ # Registers a block, a named method, or any object that responds to +call+
103
+ # to be triggered when the +event+ occurs.
104
+ def add_hook(event, hook = nil, &block)
105
+ hook = block if block #block has precedence
106
+ raise ArgumentError, 'no hook was passed' unless hook
107
+ hook = hook.to_s unless hook.respond_to?(:call)
108
+ hooks[event.to_s].unshift(hook)
109
+ hook
110
+ end
107
111
 
108
- # Registers a block, a named method, or any object that responds to +call+
109
- # to be triggered when the +event+ occurs.
110
- def add_hook(event, hook = nil, &block)
111
- hook = block if block #block has precedence
112
- raise ArgumentError, 'no hook was passed' unless hook
113
- hook = hook.to_s unless hook.respond_to?(:call)
114
- hooks[event.to_s].unshift(hook)
115
- hook
116
- end
112
+ # Removes the specified hook. Returns +nil+ if the hook wasn't found.
113
+ def remove_hook(event, hook)
114
+ return unless hooks.has_key?(event.to_s)
115
+ hook = hook.to_s unless hook.respond_to?(:call)
116
+ hooks[event.to_s].delete(hook)
117
+ end
117
118
 
118
- # Removes the specified hook. Returns +nil+ if the hook wasn't found.
119
- def remove_hook(event, hook)
120
- return unless hooks.has_key?(event.to_s)
121
- hook = hook.to_s unless hook.respond_to?(:call)
122
- hooks[event.to_s].delete(hook)
119
+ # Removes all hooks from the specified +event+.
120
+ # If an +event+ wasn't passed, removes all hooks from all events.
121
+ def clear_hooks(event = nil)
122
+ if event
123
+ hooks.delete(event.to_s) if hooks.has_key?(event.to_s)
124
+ return
123
125
  end
124
126
 
125
- # Removes all hooks from the specified +event+.
126
- # If an +event+ wasn't passed, removes all hooks from all events.
127
- def clear_hooks(event = nil)
128
- if event
129
- hooks.delete(event.to_s) if hooks.has_key?(event.to_s)
130
- return
131
- end
127
+ hooks.clear
128
+ nil
129
+ end
132
130
 
133
- hooks.clear
134
- nil
135
- end
131
+ # Generic +event+. It's called for all triggered events.
132
+ def on_changed(hook = nil, &block)
133
+ add_hook __method__, hook, &block
134
+ end
136
135
 
137
- private #--------------------------------------------------------------
136
+ private #--------------------------------------------------------------
138
137
 
139
- def hooks
140
- @hooks ||= Hash.new { |h, k| h[k.to_s] = [] }
141
- end
138
+ def hooks
139
+ @hooks ||= Hash.new { |h, k| h[k.to_s] = [] }
140
+ end
142
141
 
143
- def extract_parameters(args)
144
- raise ArgumentError, "wrong number of arguments (#{args.length} for 0..2)" if args.length > 2
145
-
146
- case
147
- when args.length == 0 # call_*s(event, caller = self, parms = {})
148
- [self, {}]
149
- when args.length == 2 # call_*s(event, caller, parms)
150
- args
151
- when [Hash, OpenStruct].include?(args[0].class) # call_*s(event, caller = self, parms)
152
- [self, args[0]]
153
- else
154
- [args[0], {}] # call_*s(event, caller, parms = {})
155
- end
142
+ def extract_parameters(args)
143
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 0..2)" if args.length > 2
144
+
145
+ case
146
+ when args.length == 0 # call_*s(event, caller = self, parms = {})
147
+ [self, {}]
148
+ when args.length == 2 # call_*s(event, caller, parms)
149
+ args
150
+ when [Hash, OpenStruct].include?(args[0].class) # call_*s(event, caller = self, parms)
151
+ [self, args[0]]
152
+ else
153
+ [args[0], {}] # call_*s(event, caller, parms = {})
156
154
  end
155
+ end
157
156
 
158
- def build_hook(hook)
159
- case hook
160
- when Proc, Method then hook
161
- when Symbol, String then caller.method(hook)
162
- else hook.method(:call)
163
- end
157
+ def build_hook(hook)
158
+ case hook
159
+ when Proc, Method then hook
160
+ when Symbol, String then caller.method(hook)
161
+ else hook.method(:call)
164
162
  end
163
+ end
165
164
 
166
- def call_hook(hook, event, caller, parms, parms2)
167
- return hook.(), parms2 if hook.arity == 0
168
- return hook.(event, caller, parms) if hook.arity > 1
165
+ def call_hook(hook, event, caller, parms, parms2)
166
+ return hook.(), parms2 if hook.arity == 0
167
+ return hook.(event, caller, parms) if hook.arity > 1
169
168
 
170
- parms = parms.to_h if parms.is_a?(OpenStruct)
171
- parms2 ||= OpenStruct.new(parms.merge(event: event, caller: caller))
172
- [ hook.(parms2), parms2 ]
173
- end
169
+ parms = parms.to_h if parms.is_a?(OpenStruct)
170
+ parms2 ||= OpenStruct.new(parms.merge(event: event, caller: caller))
171
+ [ hook.(parms2), parms2 ]
172
+ end
174
173
 
175
- def call_hooks(event, *args)
176
- invoke :hook, event, *args
177
- end
174
+ def call_hooks(event, *args)
175
+ invoke :hook, event, *args
176
+ end
178
177
 
179
- # `#call_handlers` is similar to `#call_hooks`,
180
- # but stops calling other hooks when a hook returns a value other than +nil+ or +false+.
181
- # If caller is a Hash, then use: call_*s(event, hash, {})
182
- def call_handlers(event, *args)
183
- invoke :handler, event, *args
184
- end
178
+ # `#call_handlers` is similar to `#call_hooks`,
179
+ # but stops calling other hooks when a hook returns a value other than +nil+ or +false+.
180
+ # If caller is a Hash, then use: call_*s(event, hash, {})
181
+ def call_handlers(event, *args)
182
+ invoke :handler, event, *args
183
+ end
185
184
 
186
- def invoke(type, event, *args)
187
- caller, parms = extract_parameters(args)
188
- return unless hooks.has_key?(event.to_s)
189
- handled, parms2 = nil, nil
190
- hooks[event.to_s].each do |hook|
191
- hook = build_hook(hook)
192
- handled, parms2 = call_hook(hook, event, caller, parms, parms2)
193
- break if type == :handler && handled
194
- end
195
- type == :handler && handled
185
+ def invoke(type, event, *args)
186
+ caller, parms = extract_parameters(args)
187
+ return unless hooks.has_key?(event.to_s)
188
+ handled, parms2 = nil, nil
189
+ hooks[event.to_s].each do |hook|
190
+ hook = build_hook(hook)
191
+ handled, parms2 = call_hook(hook, event, caller, parms, parms2)
192
+ break if type == :handler && handled
196
193
  end
197
- end
194
+ type == :handler && handled
195
+ end
198
196
  end
199
197
  end
@@ -3,5 +3,5 @@
3
3
  # which should have been represented by a major version number increase.
4
4
 
5
5
  module Ducktape
6
- VERSION = '0.5.1'.freeze
6
+ VERSION = '0.5.2'.freeze
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducktape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SilverPhoenix99
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-01 00:00:00.000000000 Z
12
+ date: 2015-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facets
@@ -110,7 +110,7 @@ post_install_message: |
110
110
  Thank you for choosing Ducktape.
111
111
 
112
112
  ==========================================================================
113
- 0.5.1 Changes:
113
+ 0.5.2 Changes:
114
114
  - Added Bindable::bind method to wrap BindingSource construction.
115
115
  - Added support for Range validation in bindable attributes.
116
116
  - Internal refactorings.