object_callbacks 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -1
- data/README.md +5 -2
- data/Rakefile +5 -0
- data/examples/basic_callback.rb +4 -4
- data/lib/object_callbacks.rb +5 -5
- data/lib/object_callbacks/version.rb +1 -1
- data/spec/{before_call_spec.rb → callbacks_spec.rb} +6 -6
- data/spec/spec_helper.rb +13 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f90879032ff0ba9eb0606c687610c2bc2ff5b10
|
4
|
+
data.tar.gz: 6b6c30a51cd2ceab06602327431697ae791ad049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fd008363e8c4f4525f88755a4feca7b2c34f0fa771050d61dcfee5f01b067cc315c23e83f637926d484f74cd6af6e5313e48725678c7d6d3347e4f7e886449
|
7
|
+
data.tar.gz: 0976bb6b2b80ae755a5231999ee8e4c5212927fcbafd55dae009748fa054849b7cc9cdeee825bf378fc35585e83857272f7da021fa26250b51468d4c623a0a12
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# ObjectCallbacks
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/object_callbacks)
|
4
|
+
[](https://travis-ci.org/raza/object_callbacks)
|
5
|
+
[](https://codeclimate.com/github/raza/object_callbacks)
|
6
|
+
[](https://codeclimate.com/github/raza/object_callbacks)
|
4
7
|
|
5
8
|
ActiveRecord's callbacks basic functionality, similar to BeforeFilters [**https://github.com/IDme/before_filters**] gem, with after_call and better :only, and :except clauses control.
|
6
9
|
|
@@ -32,8 +35,8 @@ class MyClass
|
|
32
35
|
extend ObjectCallbacks
|
33
36
|
|
34
37
|
before_call :sit_down
|
35
|
-
before_call :drink_one_glass, only
|
36
|
-
after_call :drink_four_glasses, only
|
38
|
+
before_call :drink_one_glass, :only => [:sleep]
|
39
|
+
after_call :drink_four_glasses, :only => [:wake_up]
|
37
40
|
|
38
41
|
def sleep
|
39
42
|
puts 'Go to sleep'
|
data/Rakefile
CHANGED
data/examples/basic_callback.rb
CHANGED
@@ -3,10 +3,10 @@ require 'object_callbacks'
|
|
3
3
|
class MyClass
|
4
4
|
extend ObjectCallbacks
|
5
5
|
|
6
|
-
before_call :before_callback_1, only
|
7
|
-
before_call :before_callback_2, only
|
8
|
-
before_call :before_callback_3, only
|
9
|
-
after_call :after_call_1, only
|
6
|
+
before_call :before_callback_1, :only => [:action1]
|
7
|
+
before_call :before_callback_2, :only => [:action1]
|
8
|
+
before_call :before_callback_3, :only => [:action1]
|
9
|
+
after_call :after_call_1, :only => [:action1]
|
10
10
|
|
11
11
|
def action1
|
12
12
|
puts 'action1 called'
|
data/lib/object_callbacks.rb
CHANGED
@@ -68,18 +68,18 @@ module ObjectCallbacks
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def callbacks_for_all(callbacks)
|
71
|
-
callbacks.select
|
71
|
+
callbacks.to_a.select{|key, value| value.empty?}.map(&:first)
|
72
72
|
end
|
73
73
|
|
74
74
|
def only_callbacks(callbacks, action_name)
|
75
|
-
callbacks.select do |_key, value|
|
75
|
+
callbacks.to_a.select do |_key, value|
|
76
76
|
!value[:only].nil? && value[:only].include?(action_name)
|
77
|
-
end.
|
77
|
+
end.map(&:first)
|
78
78
|
end
|
79
79
|
|
80
80
|
def except_callbacks(callbacks, action_name)
|
81
|
-
callbacks.select do |_key, value|
|
81
|
+
callbacks.to_a.select do |_key, value|
|
82
82
|
!value[:except].nil? && !value[:except].include?(action_name)
|
83
|
-
end.
|
83
|
+
end.map(&:first)
|
84
84
|
end
|
85
85
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'object_callbacks'
|
2
|
-
require 'pry'
|
3
3
|
|
4
4
|
class MyClass
|
5
5
|
extend ObjectCallbacks
|
6
6
|
|
7
7
|
before_call :sit_down
|
8
|
-
before_call :drink_one_glass, only
|
9
|
-
after_call :drink_four_glasses, only
|
8
|
+
before_call :drink_one_glass, :only => [:sleep]
|
9
|
+
after_call :drink_four_glasses, :only => [:wake_up]
|
10
10
|
|
11
11
|
def sleep
|
12
12
|
'Go to sleep'
|
@@ -35,17 +35,17 @@ describe ObjectCallbacks do
|
|
35
35
|
subject { MyClass.new }
|
36
36
|
describe '#sleep' do
|
37
37
|
it 'calls sit_down' do
|
38
|
-
subject.
|
38
|
+
expect(subject).to receive(:sit_down)
|
39
39
|
subject.sleep
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'drinks one glass' do
|
43
|
-
subject.
|
43
|
+
expect(subject).to receive(:drink_one_glass)
|
44
44
|
subject.sleep
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should not drink four glasses' do
|
48
|
-
subject.
|
48
|
+
expect(subject).to_not receive(:drink_four_glasses)
|
49
49
|
subject.sleep
|
50
50
|
end
|
51
51
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_callbacks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raza Ali
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
@@ -68,7 +69,8 @@ files:
|
|
68
69
|
- lib/object_callbacks.rb
|
69
70
|
- lib/object_callbacks/version.rb
|
70
71
|
- object_callbacks.gemspec
|
71
|
-
- spec/
|
72
|
+
- spec/callbacks_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
72
74
|
homepage: https://github.com/raza/object_callbacks
|
73
75
|
licenses:
|
74
76
|
- MIT
|
@@ -94,4 +96,5 @@ signing_key:
|
|
94
96
|
specification_version: 4
|
95
97
|
summary: Ruby object method callbacks
|
96
98
|
test_files:
|
97
|
-
- spec/
|
99
|
+
- spec/callbacks_spec.rb
|
100
|
+
- spec/spec_helper.rb
|