method_found 0.0.1 → 0.1.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/Gemfile +2 -0
- data/README.md +19 -23
- data/lib/method_found/interceptor.rb +17 -0
- data/lib/method_found/version.rb +1 -1
- data/lib/method_found.rb +4 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e8e38c169b46157f6c1a94856b022b110efc13
|
4
|
+
data.tar.gz: 0c0b6468a1d9e23d1238379e4963fcf37e7e5e51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664ef99573b8519bffd46a80a92183477a9d0e4c74dbffbfdba48d723ef1d90e8813b536947635706f66f05561ac22ffbffaa70f801912475deb6688127f98e6
|
7
|
+
data.tar.gz: f8dd6a6173cd3b73476ca500055e0b0d2b72de6d6f10f8a14266467dc8e227477a32a088edf4223fb4aa4ffb4d7bebf5a5a9e13ed2e70ad1b7a0f02cd6a5812b
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,35 @@
|
|
1
1
|
# MethodFound
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Intercept `method_missing` and do something useful with it.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
Add
|
7
|
+
Add to your Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem 'method_found'
|
10
|
+
gem 'method_found', '~> 0.1.0'
|
13
11
|
```
|
14
12
|
|
15
|
-
And
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install method_found
|
13
|
+
And bundle it.
|
22
14
|
|
23
15
|
## Usage
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
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.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/method_found. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
17
|
+
Include an instance of `MethodFound` with a regex to match and block which
|
18
|
+
takes the method name, regex matches, and arguments and does something with it:
|
36
19
|
|
20
|
+
```ruby
|
21
|
+
class Foo
|
22
|
+
include(MethodFound.new(/\Asay_([a-z]+)/Z/) do |method_name, matches, *arguments|
|
23
|
+
"#{matches[0]}!"
|
24
|
+
end)
|
25
|
+
end
|
26
|
+
|
27
|
+
foo = Foo.new
|
28
|
+
foo.say_hello
|
29
|
+
#=> "hello!"
|
30
|
+
foo.say_bye
|
31
|
+
#=> "bye!"
|
32
|
+
```
|
37
33
|
|
38
34
|
## License
|
39
35
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MethodFound
|
2
|
+
class Interceptor < Module
|
3
|
+
def initialize(regex, &intercept_block)
|
4
|
+
define_method :method_missing do |method_name, *arguments, &method_block|
|
5
|
+
if matches = regex.match(method_name)
|
6
|
+
instance_exec(method_name, matches, *arguments, &intercept_block)
|
7
|
+
else
|
8
|
+
super(method_name, *arguments, &method_block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
define_method :respond_to_missing? do |method_name, include_private = false|
|
13
|
+
(method_name =~ regex) || super(method_name, include_private)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/method_found/version.rb
CHANGED
data/lib/method_found.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_found
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
72
|
- lib/method_found.rb
|
73
|
+
- lib/method_found/interceptor.rb
|
73
74
|
- lib/method_found/version.rb
|
74
75
|
- method_found.gemspec
|
75
76
|
homepage: https://github.com/shioyama/method_found
|