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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a61c8959ce0b2aceec159ca529e2f3fde6b6e5ee
4
- data.tar.gz: f6e790a079d9244183e69012fa720b88d4771e18
3
+ metadata.gz: 6ca8e032aad27caac92b5ae5f3cfead907279c04
4
+ data.tar.gz: 13f3a3c3ae45be7f97aabbe436f365367d017518
5
5
  SHA512:
6
- metadata.gz: 1ba49d70657b76e9e9ec0e90f322376e786784127fc21f147c75edcc53805258f9ebad9c1c05d76aea0d8cfbfe81ee11fa71be2f21b63e2e8873ad41b6245584
7
- data.tar.gz: 1f43024320816a1de2139da56491110a692ce42bcd14333351fc1f8b0ab057b94f1603521c4492237053af6cb041c241c97a5527b296f32dc5cefa9815bfccf4
6
+ metadata.gz: 2798593f00ac3f6c0ae226c318b0dd4e7e6c497e1b7f462d4b08ec3faf04a724bc30c2f18ced994a43e31c33f59ea441cbae8192dffb3ec66bbe809fdca264d6
7
+ data.tar.gz: 3563544ebcbc7b928c2cd5389f0e4f4da011fc34cd3738f3172bc5f7eac0238adcc2dd89457afc839ab81f21b4891cbb56df3b5df209371e903f57fc14c92dc1
data/.gitignore CHANGED
@@ -12,4 +12,7 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
- *.gem
15
+ *.gem
16
+ .ruby-version
17
+ .ruby-gemset
18
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.2.2
5
+ script: bundle exec rspec
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
- TODO: Write a gem description
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 Callbacks
27
+ extend MethodHooks
26
28
 
27
29
  before :save do
28
30
  puts 'before'
data/examples/model.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Model
2
- extend Callbacks
2
+ extend MethodHooks
3
3
 
4
4
  before :save do
5
5
  puts 'before'
@@ -1,3 +1,3 @@
1
1
  module MethodHooks
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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
- return if @new_method == false || [:call_before_callbacks, :call_around_callbacks, :call_after_callbacks].include?(method_name)
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
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
23
24
  end
@@ -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.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-07 00:00:00.000000000 Z
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