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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b9a986f01ee5802f9a0de0140f43326ebc03bdf
4
- data.tar.gz: 9523ec14d089eecce4b14ec9a193cd8f42ddfe01
3
+ metadata.gz: 74409ad9fa91aaa71560415ffed1edb0fbc7cd4a
4
+ data.tar.gz: 804c467baf1edf241be682b8d745ce97755f5b9e
5
5
  SHA512:
6
- metadata.gz: ab2080b1e3e50445ddcdcb2ad95d6ffc74f71cd35e5e85bfba8fc388c971da3d246312cd2a223ff1df1b7dab310cf4e936511114839d9943ec85dc1ae4f6b756
7
- data.tar.gz: dd48e8a909e52659a22a55100c694b59b90354fe0c536b39c6b9247b7e8d6bbbeb6911b3815870f6555b61fc8dc0e0de3446b1ee297c28169cba62498e6f4cf1
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
@@ -18,6 +18,10 @@ module Bellbro
18
18
  def pool(pool_name)
19
19
  @pool_name = pool_name
20
20
  end
21
+
22
+ def pool_name
23
+ @pool_name
24
+ end
21
25
 
22
26
  def connection_pool(pool_name: nil)
23
27
  Bellbro::Settings.connection_pools[pool_name || @pool_name]
@@ -1,3 +1,3 @@
1
1
  module Bellbro
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/bellbro.rb CHANGED
@@ -10,6 +10,7 @@ require 'airbrake'
10
10
  %w(
11
11
  bellbro/settings.rb
12
12
  bellbro/hooks.rb
13
+ bellbro/keyable.rb
13
14
  bellbro/retryable.rb
14
15
  bellbro/ringable.rb
15
16
  bellbro/trackable.rb
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.0
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-09 00:00:00.000000000 Z
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