named_return 0.1.0 → 1.0.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 +4 -4
- data/README.md +5 -1
- data/lib/named_return/proxy.rb +6 -5
- data/lib/named_return/version.rb +1 -1
- data/lib/named_return/wrapped_method.rb +4 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f0e72a7eaef30e12c8bc5abfc11339f2732646
|
4
|
+
data.tar.gz: 190650a389ecfdedb126730708d1092bcb4fb774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2f2ce6f93c641021bdadc3f9f6315c9fcc11a00599707d02d3e58e5cf5d72e33fecbf8765debd17f6c6f77fe6f709b620ee9785c54eb2984ba3b4f96fd50923
|
7
|
+
data.tar.gz: a904a67f9deff795abf69b863fb8c895fafa7d9eee9db054d5e3404a343c3a3cc83721854a39e3fbb2f4b1944700faa54ba2e064e6ebdc60e0098ef0ff47be5a
|
data/README.md
CHANGED
@@ -24,6 +24,10 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
TODO: Write usage instructions here
|
26
26
|
|
27
|
+
## Thread Safety
|
28
|
+
|
29
|
+
I've used this in an app that called methods simultaneously and [it blew up but then I fixed it so] it works, thus as far as I know it's threadsafe, yay!
|
30
|
+
|
27
31
|
## Development
|
28
32
|
|
29
33
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -32,7 +36,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
36
|
|
33
37
|
## Contributing
|
34
38
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sfcgeorge/named_return.
|
36
40
|
|
37
41
|
|
38
42
|
## License
|
data/lib/named_return/proxy.rb
CHANGED
@@ -15,17 +15,18 @@ module NamedReturn
|
|
15
15
|
return unless @wrap_method == true # not just truthy, true for reals
|
16
16
|
|
17
17
|
@wrap_method = :overriding # this prevents infinite loops :P
|
18
|
-
|
19
|
-
override_method(obj, wrapped_method, singleton)
|
18
|
+
override_method(obj, meth, singleton)
|
20
19
|
@wrap_method = nil
|
21
20
|
end
|
22
21
|
|
23
22
|
private
|
24
23
|
|
25
|
-
def override_method(obj,
|
24
|
+
def override_method(obj, meth, singleton)
|
26
25
|
base = self
|
27
|
-
|
28
|
-
|
26
|
+
config = self.config
|
27
|
+
obj.send(:"define#{singleton}_method", meth.name) do |*args, &block|
|
28
|
+
# WrappedMethod.new needs to be here for thread safety
|
29
|
+
wrapped = WrappedMethod.new(meth, config, self)
|
29
30
|
# skip the magic if test mode is on
|
30
31
|
return wrapped.call_original(*args, &block) if base.config.test
|
31
32
|
|
data/lib/named_return/version.rb
CHANGED
@@ -4,9 +4,12 @@ module NamedReturn
|
|
4
4
|
attr_reader :config
|
5
5
|
|
6
6
|
# Wrap a method with catch DSL and pass in config.
|
7
|
-
def initialize(method, config)
|
7
|
+
def initialize(method, config, bind)
|
8
8
|
@method = method
|
9
9
|
@config = config
|
10
|
+
@callbacks = {}
|
11
|
+
@response = {}
|
12
|
+
bind(bind)
|
10
13
|
end
|
11
14
|
|
12
15
|
# Get wrapped method name.
|
@@ -19,13 +22,6 @@ module NamedReturn
|
|
19
22
|
@callbacks[label] = block
|
20
23
|
end
|
21
24
|
|
22
|
-
# Prepare for next run.
|
23
|
-
def reset(bind)
|
24
|
-
@callbacks = {}
|
25
|
-
@response = {}
|
26
|
-
bind(bind)
|
27
|
-
end
|
28
|
-
|
29
25
|
# Call the wrapped method with catches inserted by the DSL.
|
30
26
|
def call(*args, &block)
|
31
27
|
return_pair = recursive_catch(@callbacks.to_a, *args, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: named_return
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon George
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|