forwardable-extended 2.4.3 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 358e5f1ae11b0c4aef42ef9fe0cb9a715072567d
4
- data.tar.gz: c04370f5d7cd533bfe8d2615818d0ca4ed08182e
3
+ metadata.gz: a0bf26e6d3a0d6c8702033209c8cc78dd66e91b8
4
+ data.tar.gz: cff44e0ccbc27734e5b7537f1bfb7ab00699d6af
5
5
  SHA512:
6
- metadata.gz: 74df3a5ede82a5094b3d0d21636b69ac1579c5f75bbddbf24b02bc0dbd26056794962302bfe7983ae0cb2333e3c25f3e18c451f3fdff5da078f7ef272f72adec
7
- data.tar.gz: cc66189537e5f8ca95ce0cc44a568cef86b4c828206585bc795ebf4c2662f9839679d1ae2ecd95c438672cb1a5f738944dd24065f2b025ae7c089004b2e396c4
6
+ metadata.gz: 956f7150e5cf3d1c008debc814333c1b15b6447dce17857a7a6593bea964e76f0d1d74f68e8828ed9dce6bd5cb309d0dc9069539aaea12635ea1374b1aef137f
7
+ data.tar.gz: 1067a33f3dbaa30926b9f52a01a6031160a2864a98b4b74a7d80745680f20a47936d612f4c3337903524865fb576d5973d84af91d14c0e4ba84fe6079d688353
@@ -1,8 +1,6 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2015-2016 Jordon Bedwell - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  require "forwardable/extended/version"
8
6
  require "forwardable"
@@ -10,10 +8,9 @@ require "forwardable"
10
8
  module Forwardable
11
9
  module Extended
12
10
 
13
- # ------------------------------------------------------------------------
14
11
  # Make our methods private on the class, there is no reason for public.
15
- # ------------------------------------------------------------------------
16
-
12
+ # This makes it so that things are cleaner to view when inside of REPL's/Debuggers.
13
+ # That way you don't see our methods without asking to see them.
17
14
  def self.extended(klass)
18
15
  instance_methods.each do |method|
19
16
  klass.private_class_method(
@@ -22,10 +19,10 @@ module Forwardable
22
19
  end
23
20
  end
24
21
 
25
- # ------------------------------------------------------------------------
26
- # A simpler delegator that wraps around `def_delegator` and makes it easy.
27
- # ------------------------------------------------------------------------
28
-
22
+ # Delegate using a Rails-like interface.
23
+ # to - the class (object) you are delegating to.
24
+ # alias_of - the method of the class (by default it's the method.)
25
+ # method - the method you are forwarding.
29
26
  def rb_delegate(method, to: nil, alias_of: method, **kwd)
30
27
  raise ArgumentError, "to must be provided" unless to
31
28
  def_delegator(
@@ -33,14 +30,12 @@ module Forwardable
33
30
  )
34
31
  end
35
32
 
36
- # ------------------------------------------------------------------------
37
- # Delegates a method to a `hash[key]`.
38
- # @param [Symbol] key used if method is an alias; disignates the hash key.
39
- # @param [Hash] hash the hash object you wish to delegate to.
40
- # ------------------------------------------------------------------------
41
-
33
+ # Delegate a method to a hash and key.
34
+ # key - the key to use if the method is not the key.
35
+ # method - the name of the method you wish to create.
36
+ # hash - the hash you are delegating to.
42
37
  def def_hash_delegator(hash, method, key: method, **kwd)
43
- prefix, suffix, wrap = __prepare(**kwd)
38
+ prefix, suffix, wrap = prepare_delegate(**kwd)
44
39
 
45
40
  if suffix
46
41
  method = method.to_s.gsub(
@@ -66,15 +61,12 @@ module Forwardable
66
61
  STR
67
62
  end
68
63
 
69
- # ------------------------------------------------------------------------
70
- # Delegates a method to an instance variable.
71
- # @note if you are not using an alias or booleans use `attr_reader`.
72
- # @param [String, Symbol] ivar the instance variable.
73
- # @param [String, Symbol] alias_ the alias.
74
- # ------------------------------------------------------------------------
75
-
64
+ # Delegate a method to an instance variable.
65
+ # ivar - the instance variable you are aliasing.
66
+ # alias_ - alias it to another method name.
67
+ # Note: If you are not doing booleans then don't bother with this.
76
68
  def def_ivar_delegator(ivar, alias_ = ivar, **kwd)
77
- prefix, suffix, wrap = __prepare(**kwd)
69
+ prefix, suffix, wrap = prepare_delegate(**kwd)
78
70
 
79
71
  if suffix
80
72
  alias_ = alias_.to_s.gsub(
@@ -100,17 +92,14 @@ module Forwardable
100
92
  STR
101
93
  end
102
94
 
103
- # ------------------------------------------------------------------------
104
- # A more beefed up version of Ruby's `def_delegator` that
105
- # offers a tiny bit more than the default version in `Forwardable`
106
- # @param [Object<>] accessor the object to ship your method to.
107
- # @param [String, Symbol] method the method being messaged.
108
- # @param [Array<>] args the arguments to place in front.
109
- # ------------------------------------------------------------------------
110
-
95
+ # method - the method you wish to delegate.
96
+ # alias_ - the name of the method on the current object.
97
+ # args - arguments to pass to the method. Note: these are inspected.
98
+ # Like def_delegator but allows you to send args and do other stuff.
99
+ # accessor - the object you wish to delegate to.
111
100
  def def_modern_delegator(accessor, method, alias_ = method, args: [], **kwd)
112
101
  args = [args].flatten.compact.map(&:to_s).unshift("").join(", ")
113
- prefix, suffix, wrap = __prepare(**kwd)
102
+ prefix, suffix, wrap = prepare_delegate(**kwd)
114
103
 
115
104
  if suffix
116
105
  alias_ = alias_.to_s.gsub(
@@ -136,12 +125,7 @@ module Forwardable
136
125
  STR
137
126
  end
138
127
 
139
- # ------------------------------------------------------------------------
140
- # Wraps around traditional def_delegator to offer forwarding to modern,
141
- # ivar and hash delegators. With a bit of data checking between.
142
- # @see `Object::Forwardable#def_delegator`
143
- # ------------------------------------------------------------------------
144
-
128
+ # Wraps around traditional delegation and modern delegation.
145
129
  def def_delegator(accessor, method, alias_ = method, **kwd)
146
130
  kwd, alias_ = alias_, method if alias_.is_a?(Hash) && !kwd.any?
147
131
 
@@ -155,18 +139,14 @@ module Forwardable
155
139
  )
156
140
 
157
141
  else
158
- raise ArgumentError, "Alias not supported with type" if alias_ != method
159
- send("def_#{kwd[:type]}_delegator", accessor, method, **kwd.tap { |obj|
142
+ raise ArgumentError, "Alias not supported." if alias_ != method
143
+ send("def_#{kwd[:type]}_delegator", accessor, method, **kwd.tap do |obj|
160
144
  obj.delete(:type)
161
- })
145
+ end)
162
146
  end
163
147
  end
164
148
 
165
- # ------------------------------------------------------------------------
166
- # Wraps around traditional `def_delegators` to detect hash arguments.
167
- # @see `Object::Forwardable#def_delegators`
168
- # ------------------------------------------------------------------------
169
-
149
+ # Create multiple delegates at once.
170
150
  def def_delegators(accessor, *methods)
171
151
  kwd = methods.shift if methods.first.is_a?(Hash)
172
152
  kwd = methods.pop if methods. last.is_a?(Hash)
@@ -177,14 +157,10 @@ module Forwardable
177
157
  end
178
158
  end
179
159
 
180
- # ------------------------------------------------------------------------
181
- # Prepares the suffix, prefix and wrap method if available.
182
- # @param [true, false, :reverse] bool whether or not this is a boolean.
183
- # @param [true, Symbol, String] wrap wrap result into the wrap.
184
- # ------------------------------------------------------------------------
185
-
186
- private
187
- def __prepare(wrap: nil, bool: false)
160
+ # Prepares a delegate and it's few arguments.
161
+ # wrap - whether to wrap (or the class to wrap it with.)
162
+ # bool - whether or not this delegate is a boolean.
163
+ private def prepare_delegate(wrap: nil, bool: false)
188
164
  prefix = (bool == :reverse ? "!!!" : "!!") if bool
189
165
  wrap = "self.class.new" if wrap.is_a?(TrueClass)
190
166
  suffix = "?" if bool
@@ -4,6 +4,6 @@
4
4
 
5
5
  module Forwardable
6
6
  module Extended
7
- VERSION = "2.4.3"
7
+ VERSION = "2.5.0"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forwardable-extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Forwardable with hash, and instance variable extensions.
14
14
  email:
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  version: '0'
43
43
  requirements: []
44
44
  rubyforge_project:
45
- rubygems_version: 2.5.2
45
+ rubygems_version: 2.5.1
46
46
  signing_key:
47
47
  specification_version: 4
48
48
  summary: Forwardable with hash, and instance variable extensions.