bellbro 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/lib/bellbro/keyable.rb +70 -0
- data/lib/bellbro/pool.rb +4 -0
- data/lib/bellbro/version.rb +1 -1
- data/lib/bellbro.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74409ad9fa91aaa71560415ffed1edb0fbc7cd4a
|
4
|
+
data.tar.gz: 804c467baf1edf241be682b8d745ce97755f5b9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db86de1aeeb29d4f40c8da9ecbf895b43923c7b9ae6abdb347dd76e2c1e0593d70b11c2407ef927aefa041447734de8880e24f6dfe36196704c22041982b9a6d
|
7
|
+
data.tar.gz: 4063b6d5ff173284fb7dfc267ac0d1652eb3a7c9a4437f90536cedc26d706b0c55c52ad680d7eda54b9d8affcaf51ad79c2d621894177a60b1d566c86556b20a
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Bellbro
|
2
|
+
module Keyable
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
extend ClassMethods
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def respond_to?(method)
|
10
|
+
return true if @respond_to && @respond_to.include?(method.to_sym)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def delegate_all_keys(*methods)
|
16
|
+
delegate_getter_keys(*methods)
|
17
|
+
delegate_setter_keys(*methods)
|
18
|
+
delegate_status_keys(*methods)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delegate_getter_keys(*methods)
|
22
|
+
options = extract_methods(methods)
|
23
|
+
options[:methods].each do |key|
|
24
|
+
@respond_to << key
|
25
|
+
define_method key do
|
26
|
+
send(options[:to])[key]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def delegate_setter_keys(*methods)
|
32
|
+
options = extract_methods(methods)
|
33
|
+
options[:methods].each do |key|
|
34
|
+
@respond_to << "#{key}="
|
35
|
+
define_method "#{key}=" do |value|
|
36
|
+
send(options[:to])[key] = value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def delegate_status_keys(*methods)
|
42
|
+
options = extract_methods(methods)
|
43
|
+
options[:methods].each do |key|
|
44
|
+
@respond_to << "#{key}?"
|
45
|
+
define_method "#{key}?" do
|
46
|
+
!!send(options[:to])[key]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def extract_methods(methods)
|
54
|
+
options = methods.pop
|
55
|
+
unless options.is_a?(Hash) && to = options[:to].try(:to_sym)
|
56
|
+
raise ArgumentError, 'Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, to: :greeter).'
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set up the data hash, if needed
|
60
|
+
if respond_to?(to) && !send(to).respond_to?(:[]) && !send(to).respond_to?(:[]=)
|
61
|
+
raise ArgumentError, 'Target must be a hash-like object.'
|
62
|
+
end
|
63
|
+
|
64
|
+
@respond_to ||= []
|
65
|
+
{ methods: methods.map(&:to_sym), to: to }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/bellbro/pool.rb
CHANGED
data/lib/bellbro/version.rb
CHANGED
data/lib/bellbro.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bellbro
|
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
|
- Jon Stokes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/bellbro.rb
|
139
139
|
- lib/bellbro/bell.rb
|
140
140
|
- lib/bellbro/hooks.rb
|
141
|
+
- lib/bellbro/keyable.rb
|
141
142
|
- lib/bellbro/pool.rb
|
142
143
|
- lib/bellbro/retryable.rb
|
143
144
|
- lib/bellbro/ringable.rb
|