ducktape 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTdhMjYxMTNjNWZmOTYwOWEwZjI0ZGU2OTQxOTYyYTgxYTUzOTQwNw==
5
+ data.tar.gz: !binary |-
6
+ ZTViZThkYWZiNGRiNjI3NGRmZTg1NTUzMzc3ZjIwMGEwNzVjYjc5MA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MWIxOWMxOWVkNWZlMWFlNzA4OWUzMDU5MDljNzBhNWI4ZDBlZTJkZWUyN2Ji
10
+ M2Y5NmJiN2UxZmZjMmIxNWM0ZmI0OTM2MWQyZTE4MDg5ODdlZTQxYTU3N2Ez
11
+ YmVkM2EzMjU4MDViMmY0M2RhNDgxYTgyNmM4ZDg1MDU0NmVlZWM=
12
+ data.tar.gz: !binary |-
13
+ YTk1NTYxN2NjNDgwMmI2NTJkMmU4MGQyNTYzZjFlNDU1NzdkOGQ5MDJlNjc3
14
+ ZDQwM2M2MDUzOTkyN2QyNmU0YTk4ZjhjOTJkNDhiZGZmOThkOWIyYjU3ZmYz
15
+ MzhjOWM5NDhhODdkZWIwZjBlNTI3N2NmOTFlNzAzNDgzYTY1MmU=
data/README.md CHANGED
@@ -1,13 +1,42 @@
1
1
  # ducktape
2
2
 
3
- A [truly outrageous](http://youtu.be/dSPb56-_I98) gem for bindable attributes and event notification.
3
+ * https://github.com/SilverPhoenix99/ducktape
4
+
5
+ <a href='http://www.pledgie.com/campaigns/18955'><img alt='Click here to lend your support to: ducktape and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/18955.png?skin_name=chrome' border='0' /></a>
6
+
7
+ ## INSTALL:
4
8
 
5
- To install:
9
+ gem install ducktape
10
+
11
+ ## DESCRIPTION:
12
+
13
+ A [truly outrageous](http://youtu.be/dSPb56-_I98) gem for bindable attributes and event notification.
6
14
 
7
- ```
8
- gem install ducktape
9
- ```
15
+ ## SYNOPSIS:
10
16
 
11
17
  Additional documentation can be found in the [Wiki](https://github.com/SilverPhoenix99/ducktape/wiki).
12
18
 
13
- <a href='http://www.pledgie.com/campaigns/18955'><img alt='Click here to lend your support to: ducktape and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/18955.png?skin_name=chrome' border='0' /></a>
19
+ ## LICENSE:
20
+
21
+ (The MIT License)
22
+
23
+ Copyright &copy; 2012 Pedro Pinto
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining
26
+ a copy of this software and associated documentation files (the
27
+ 'Software'), to deal in the Software without restriction, including
28
+ without limitation the rights to use, copy, modify, merge, publish,
29
+ distribute, sublicense, and/or sell copies of the Software, and to
30
+ permit persons to whom the Software is furnished to do so, subject to
31
+ the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be
34
+ included in all copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
37
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
39
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
40
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -36,7 +36,8 @@ module Ducktape
36
36
  name = name.to_s
37
37
  m = bindings_metadata[name]
38
38
  return m if m
39
- return nil unless superclass.respond_to?(:metadata) && (m = superclass.metadata(name))
39
+ a = ancestors.find { |a| a != self && a.respond_to?(:metadata) }
40
+ return nil unless a && (m = a.metadata(name))
40
41
  m = m.dup
41
42
  bindings_metadata[name] = m
42
43
  end
@@ -49,6 +50,12 @@ module Ducktape
49
50
 
50
51
  def self.included(base)
51
52
  base.extend(ClassMethods)
53
+ return unless base.is_a?(Module)
54
+ included = base.respond_to?(:included) && base.method(:included)
55
+ base.define_singleton_method(:included, ->(c) do
56
+ included.(c) if included
57
+ c.extend(ClassMethods)
58
+ end)
52
59
  end
53
60
 
54
61
  def self.extended(_)
@@ -3,17 +3,14 @@ module Ducktape
3
3
 
4
4
  module ClassMethods
5
5
  def def_hook(*events)
6
- events.each { |e| define_method e, ->(method_name = nil, &block){ add_hook(e, method_name, &block) } }
6
+ events.each { |e| define_method e, ->(method_name = nil, &block) { add_hook(e, method_name, &block) } }
7
7
  end
8
8
 
9
9
  %w'hook handler'.each do |type|
10
10
  define_method "make_#{type}s" do |*args|
11
11
  return if args.length == 0
12
12
 
13
- #def_hook 'on_changed' unless method_defined?('on_changed')
14
-
15
- names_hash = args.pop if args.last.is_a?(Hash)
16
- names_hash ||= {}
13
+ names_hash = (args.last.is_a?(Hash) && args.pop) || {}
17
14
 
18
15
  #Reversed merge because names_hash has priority.
19
16
  names_hash = Hash[args.flatten.map { |v| [v, v] }].merge!(names_hash)
@@ -27,8 +24,8 @@ module Ducktape
27
24
  define_method(name) do |*a, &block|
28
25
  bm = um.bind(self)
29
26
  r = bm.(*a, &block)
30
- if !send(cm, aka, self, event: name, args: a, result: r) || type != 'handler'
31
- send( cm, 'on_changed', self, event: name, args: a, result: r)
27
+ if !send(cm, aka, name, OpenStruct.new(args: a, result: r)) || type != 'handler'
28
+ send( cm, :on_changed, name, OpenStruct.new(args: a, result: r))
32
29
  end
33
30
  r
34
31
  end
@@ -39,7 +36,13 @@ module Ducktape
39
36
 
40
37
  def self.included(base)
41
38
  base.extend(ClassMethods)
42
- base.def_hook :on_changed unless base.method_defined? :on_changed
39
+ base.def_hook :on_changed unless base.method_defined?(:on_changed)
40
+ return unless base.is_a?(Module)
41
+ included = base.respond_to?(:included) && base.method(:included)
42
+ base.define_singleton_method(:included, ->(c) do
43
+ included.(c) if included
44
+ c.extend(ClassMethods)
45
+ end)
43
46
  end
44
47
 
45
48
  def self.extended(_)
@@ -48,14 +51,14 @@ module Ducktape
48
51
 
49
52
  def add_hook(event, hook = nil, &block)
50
53
  hook = block if block #block has precedence
51
- return unless hook
52
- hook = hook.to_s unless hook.respond_to?('call')
54
+ raise ArgumentError, 'no hook was passed' unless hook
55
+ hook = hook.to_s unless hook.respond_to?(:call)
53
56
  self.hooks[event.to_s].unshift(hook)
54
57
  hook
55
58
  end
56
59
 
57
60
  def remove_hook(event, hook)
58
- hook = hook.to_s unless hook.respond_to?('call')
61
+ hook = hook.to_s unless hook.respond_to?(:call)
59
62
  self.hooks[event.to_s].delete(hook)
60
63
  end
61
64
 
@@ -75,14 +78,36 @@ module Ducktape
75
78
 
76
79
  # `#call_handlers` is similar to `#call_hooks`,
77
80
  # but stops calling other hooks when a hook returns a value other than nil or false.
78
- %w'hook handler'.each do |type|
79
- define_method("call_#{type}s", ->(event, caller = self, parms = {}) do
80
- return unless self.hooks.has_key? event.to_s
81
- self.hooks[event.to_s].each do |hook|
82
- hook = caller.method(hook) unless hook.respond_to?('call')
83
- handled = hook.(event, caller, parms)
84
- break handled if type == 'handler' && handled
81
+ # If caller is a Hash, then use: call_*s(event, hash, {})
82
+ %w'hook handler'.each do |name|
83
+ define_method("call_#{name}s", ->(event, *args) do
84
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 3)" if args.length > 2
85
+ caller, parms = case
86
+ when args.length == 0 then [self, {}] # call_*s(event, caller = self, parms = {})
87
+ when args.length == 2 then args # call_*s(event, caller, parms)
88
+ when [Hash, OpenStruct].any? { |c| c === args[0] } then [self, args[0]] # call_*s(event, caller = self, parms)
89
+ else [args[0], {}] # call_*s(event, caller, parms = {})
90
+ end
91
+
92
+ return unless hooks.has_key?(event.to_s)
93
+
94
+ handled, parms2 = nil, nil
95
+ hooks[event.to_s].each do |hook|
96
+ hook = case hook
97
+ when Proc, Method then hook
98
+ when Symbol, String then caller.method(hook)
99
+ else hook.method(:call)
100
+ end
101
+ handled = if hook.arity == 1
102
+ parms2 ||= OpenStruct.new(
103
+ (parms.is_a?(OpenStruct) ? parms.to_h : parms).merge(event: event, caller: caller))
104
+ hook.(parms2)
105
+ else
106
+ hook.(event, caller, parms)
107
+ end
108
+ break if name.index('handler') && handled
85
109
  end
110
+ name.index('handler') && handled
86
111
  end)
87
112
  end
88
113
  end
@@ -0,0 +1,7 @@
1
+ # Although against rubygems recommendation, while version is < 1.0.0, an increase in the minor version number
2
+ # may represent an incompatible implementation with the previous minor version, which should have been
3
+ # represented by a major version number increase.
4
+
5
+ module Ducktape
6
+ VERSION = '0.3.3'.freeze
7
+ end
data/lib/ducktape.rb CHANGED
@@ -1,18 +1,15 @@
1
- module Ducktape
2
- # Although against rubygems recommendation, while version is < 1.0.0, an increase in the minor version number
3
- # may represent an incompatible implementation with the previous minor version, which should have been
4
- # represented by a major version number increase.
5
-
6
- VERSION = '0.3.2'
7
-
8
- camelize = ->(f){ f.gsub(/(^|_)([^_]+)/) { |_| $2.capitalize } }
9
-
10
- %w'ducktape'.each do |dir|
11
- Dir["#{File.expand_path("../#{dir}", __FILE__)}/*.rb"].
12
- map { |f| File.basename(f, File.extname(f)) }.
13
- each { |f| autoload camelize.(f), "#{dir}/#{f}" }
14
- end
15
-
16
- %w'def_hookable'.each { |f| require "ext/#{f}" }
17
-
18
- end
1
+ %w'
2
+ set
3
+ facets/ostruct
4
+ '.each { |f| require f }
5
+
6
+ %w'
7
+ version
8
+ hookable
9
+ binding_source
10
+ bindable_attribute_metadata
11
+ bindable_attribute
12
+ bindable
13
+ '.each { |f| require "ducktape/#{f}" }
14
+
15
+ %w'def_hookable'.each { |f| require "ext/#{f}" }
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducktape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
5
- prerelease:
4
+ version: 0.3.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - SilverPhoenix99
@@ -10,8 +9,22 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-12-27 00:00:00.000000000 Z
14
- dependencies: []
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: facets
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '2.9'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '2.9'
15
28
  description: Truly outrageous bindable attributes
16
29
  email:
17
30
  - silver.phoenix99@gmail.com
@@ -28,32 +41,32 @@ files:
28
41
  - lib/ducktape/ext/hash.rb
29
42
  - lib/ducktape/ext/string.rb
30
43
  - lib/ducktape/hookable.rb
44
+ - lib/ducktape/version.rb
31
45
  - lib/ducktape.rb
32
46
  - lib/ext/def_hookable.rb
33
47
  - README.md
34
48
  homepage: https://github.com/SilverPhoenix99/ducktape
35
49
  licenses: []
50
+ metadata: {}
36
51
  post_install_message:
37
52
  rdoc_options: []
38
53
  require_paths:
39
54
  - lib
40
55
  required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
56
  requirements:
43
57
  - - ! '>='
44
58
  - !ruby/object:Gem::Version
45
59
  version: '0'
46
60
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
61
  requirements:
49
62
  - - ! '>='
50
63
  - !ruby/object:Gem::Version
51
64
  version: '0'
52
65
  requirements: []
53
66
  rubyforge_project:
54
- rubygems_version: 1.8.24
67
+ rubygems_version: 2.0.2
55
68
  signing_key:
56
- specification_version: 3
69
+ specification_version: 4
57
70
  summary: Truly outrageous bindable attributes
58
71
  test_files: []
59
72
  has_rdoc: