method_hooks 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/.travis.yml +5 -0
- data/README.md +5 -3
- data/examples/model.rb +1 -1
- data/lib/method_hooks/version.rb +1 -1
- data/lib/method_hooks.rb +2 -1
- data/method_hooks.gemspec +1 -0
- data/spec/lib/method_hooks_spec.rb +22 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ca8e032aad27caac92b5ae5f3cfead907279c04
|
4
|
+
data.tar.gz: 13f3a3c3ae45be7f97aabbe436f365367d017518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2798593f00ac3f6c0ae226c318b0dd4e7e6c497e1b7f462d4b08ec3faf04a724bc30c2f18ced994a43e31c33f59ea441cbae8192dffb3ec66bbe809fdca264d6
|
7
|
+
data.tar.gz: 3563544ebcbc7b928c2cd5389f0e4f4da011fc34cd3738f3172bc5f7eac0238adcc2dd89457afc839ab81f21b4891cbb56df3b5df209371e903f57fc14c92dc1
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/fbonetti/method_hooks.svg?branch=master)](https://travis-ci.org/fbonetti/method_hooks)
|
2
|
+
|
1
3
|
# MethodHooks
|
2
4
|
|
3
|
-
|
5
|
+
Allows you to add `before`, `around`, and `after` callbacks to **any** method.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -20,9 +22,9 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
```
|
25
|
+
```ruby
|
24
26
|
class Model
|
25
|
-
extend
|
27
|
+
extend MethodHooks
|
26
28
|
|
27
29
|
before :save do
|
28
30
|
puts 'before'
|
data/examples/model.rb
CHANGED
data/lib/method_hooks/version.rb
CHANGED
data/lib/method_hooks.rb
CHANGED
@@ -10,7 +10,8 @@ module MethodHooks
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def method_added(method_name)
|
13
|
-
|
13
|
+
super
|
14
|
+
return if @new_method == false || [:initialize, :call_before_callbacks, :call_around_callbacks, :call_after_callbacks].include?(method_name)
|
14
15
|
|
15
16
|
method = instance_method(method_name)
|
16
17
|
undef_method(method_name)
|
data/method_hooks.gemspec
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pry'
|
3
2
|
|
4
3
|
describe MethodHooks do
|
5
4
|
|
6
5
|
before do
|
7
6
|
Object.send(:remove_const, :Base) if Object.const_defined?(:Base)
|
8
7
|
|
8
|
+
module AnotherModuleWIthMethodAddedHook
|
9
|
+
def method_added(method_name)
|
10
|
+
_methods << method_name
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def _methods
|
15
|
+
@_methods ||= []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
class Base
|
20
|
+
|
21
|
+
extend AnotherModuleWIthMethodAddedHook
|
10
22
|
extend MethodHooks
|
11
23
|
|
12
24
|
attr_reader :events
|
@@ -82,4 +94,13 @@ describe MethodHooks do
|
|
82
94
|
|
83
95
|
end
|
84
96
|
|
97
|
+
it 'does not override existing .method_added hook' do
|
98
|
+
Base.class_eval do
|
99
|
+
def some_method
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(Base._methods).to include(:some_method)
|
104
|
+
end
|
105
|
+
|
85
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
41
55
|
description: Rails-style method hooks for plain old Ruby objects
|
42
56
|
email:
|
43
57
|
- frank.r.bonetti@gmail.com
|
@@ -47,6 +61,7 @@ extra_rdoc_files: []
|
|
47
61
|
files:
|
48
62
|
- .gitignore
|
49
63
|
- .rspec
|
64
|
+
- .travis.yml
|
50
65
|
- Gemfile
|
51
66
|
- LICENSE.txt
|
52
67
|
- README.md
|