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 +4 -4
- data/README.md +2 -2
- data/lib/ducktape/bindable_attribute_metadata.rb +2 -2
- data/lib/ducktape/hookable.rb +78 -80
- data/lib/ducktape/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc41d10e9abd72c09e3cafefeaef59e8fc37a6c8
|
4
|
+
data.tar.gz: 802765ccaa3a370f4dc230b9289dcfea395f80c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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](
|
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) }
|
89
|
+
validator_class = @validators.find { |validator_class| validator_class.matches?(validator) }
|
90
90
|
validator_class.new(validator)
|
91
91
|
end
|
92
92
|
|
data/lib/ducktape/hookable.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
hooks
|
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
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
136
|
+
private #--------------------------------------------------------------
|
138
137
|
|
139
|
-
|
140
|
-
|
141
|
-
|
138
|
+
def hooks
|
139
|
+
@hooks ||= Hash.new { |h, k| h[k.to_s] = [] }
|
140
|
+
end
|
142
141
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
174
|
+
def call_hooks(event, *args)
|
175
|
+
invoke :hook, event, *args
|
176
|
+
end
|
178
177
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
194
|
+
type == :handler && handled
|
195
|
+
end
|
198
196
|
end
|
199
197
|
end
|
data/lib/ducktape/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|