super_callbacks 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 +5 -5
- data/.ruby-version +1 -0
- data/.travis.yml +1 -1
- data/README.md +5 -5
- data/lib/super_callbacks/version.rb +1 -1
- data/lib/super_callbacks.rb +10 -10
- data/super_callbacks.gemspec +1 -1
- metadata +5 -5
- data/Gemfile.lock +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39773c4b3169e56de61be4f51296349b7a984ced
|
4
|
+
data.tar.gz: c4584d56aec09b2057bda2da51f68faaddaf3d32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c05e4fac9fc819123b51ec67c36808d85246b2ee737fbab8e446a954d8150cca36f463bca7f87f4a36385b6e6dcc2b554d5bed9f4d43e022d1947d7c4129fd5
|
7
|
+
data.tar.gz: 05090fb64e346e02f89109c907f3aefb2ccc6bf97e2a705b2f10d19d47fe080b57656d0da981e200338a046b80399a66193a381f00ebff1ccdbf0b2b74a526c2
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
* Supports both class and instance level callbacks
|
7
7
|
* Supports conditional callbacks
|
8
8
|
* Supports inherited callbacks; hence named "Super", get it? :D haha!
|
9
|
-
|
9
|
+
---
|
10
10
|
* Focuses on performance and flexibility as intended primarily for game development, and event-driven apps
|
11
11
|
* Standalone; no other gem dependencies
|
12
12
|
* `super_callbacks` is the upgraded version of my other repo [`dragon_ruby_callbacks`](https://github.com/jrpolidario/dragonruby_callbacks)
|
@@ -316,12 +316,12 @@ foo.bar
|
|
316
316
|
|
317
317
|
sub_foo = SubFoo.new
|
318
318
|
sub_foo.bar
|
319
|
-
# => 'SubFoo: bar'
|
320
319
|
# => 'Foo: before bar 1!'
|
320
|
+
# => 'SubFoo: bar'
|
321
321
|
# => 'bar!'
|
322
322
|
```
|
323
323
|
|
324
|
-
*Notice above `sub_foo` calls both `before` callbacks defined in `Foo` and `SubFoo`, because SubFoo inherits from Foo. Callbacks are called in order of ancestors
|
324
|
+
*Notice above `sub_foo` calls both `before` callbacks defined in `Foo` and `SubFoo`, because SubFoo inherits from Foo. Callbacks are called in order of ancestors descending; meaning it starts calling the top-level ancestor superclass callbacks, and then calling its subclass callbacks, until it reaches the instance's class callbacks*
|
325
325
|
*Above uses `before`, but works similarly with `after`*
|
326
326
|
|
327
327
|
|
@@ -344,8 +344,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
344
344
|
|
345
345
|
## Changelog
|
346
346
|
|
347
|
-
* 1.0.
|
348
|
-
* Cleaner code without explicitly calling `run_callbacks` anymore; done now because of ruby upgrade from 1.9 to 2.0+ which already supports `prepend`
|
347
|
+
* 1.0.1 (2019-08-12)
|
348
|
+
* Cleaner code without explicitly calling `run_callbacks` anymore; done now because of ruby upgrade from 1.9 to 2.0+ which already supports `prepend`
|
349
349
|
* Supported both class and instance level callbacks
|
350
350
|
* Supported inherited callbacks
|
351
351
|
* v0.2.1 (2019-08-09) *From `dragonruby_callbacks`*
|
data/lib/super_callbacks.rb
CHANGED
@@ -6,13 +6,13 @@ module SuperCallbacks
|
|
6
6
|
VALID_OPTION_KEYS = [:if].freeze
|
7
7
|
|
8
8
|
def self.included(base)
|
9
|
-
base.singleton_class.attr_accessor :before_callbacks, :after_callbacks
|
10
|
-
base.attr_accessor :before_callbacks, :after_callbacks
|
9
|
+
base.singleton_class.send :attr_accessor, *[:before_callbacks, :after_callbacks]
|
10
|
+
base.send :attr_accessor, *[:before_callbacks, :after_callbacks]
|
11
11
|
base.extend ClassMethods
|
12
|
-
base.include InstanceMethods
|
12
|
+
base.send :include, InstanceMethods
|
13
13
|
base.extend ClassAndInstanceMethods
|
14
|
-
base.include ClassAndInstanceMethods
|
15
|
-
base.prepend Prepended.new
|
14
|
+
base.send :include, ClassAndInstanceMethods
|
15
|
+
base.send :prepend, Prepended.new
|
16
16
|
end
|
17
17
|
|
18
18
|
class Prepended < Module
|
@@ -88,8 +88,8 @@ module SuperCallbacks
|
|
88
88
|
_callbacks_prepended_module_instance = callbacks_prepended_module_instance
|
89
89
|
|
90
90
|
# dont redefine, to save cpu cycles
|
91
|
-
unless
|
92
|
-
|
91
|
+
unless _callbacks_prepended_module_instance.method_defined? method_name
|
92
|
+
_callbacks_prepended_module_instance.send(:define_method, method_name) do |*args|
|
93
93
|
run_before_callbacks(method_name, *args)
|
94
94
|
super_value = super(*args)
|
95
95
|
run_after_callbacks(method_name, *args)
|
@@ -120,7 +120,7 @@ module SuperCallbacks
|
|
120
120
|
|
121
121
|
# dont redefine, to save cpu cycles
|
122
122
|
unless _callbacks_prepended_module_instance.method_defined? method_name
|
123
|
-
_callbacks_prepended_module_instance.define_method method_name do |*args|
|
123
|
+
_callbacks_prepended_module_instance.send(:define_method, method_name) do |*args|
|
124
124
|
run_before_callbacks(method_name, *args)
|
125
125
|
super_value = super(*args)
|
126
126
|
run_after_callbacks(method_name, *args)
|
@@ -147,7 +147,7 @@ module SuperCallbacks
|
|
147
147
|
# TODO: optimize by instead of dynamically getting all_ancestral_after_callbacks on runtime
|
148
148
|
# set them immediately when `include` is called on Base class
|
149
149
|
def run_before_callbacks(method_name, *args)
|
150
|
-
all_ancestral_before_callbacks = self.class.ancestors.each_with_object({}) do |ancestor, hash|
|
150
|
+
all_ancestral_before_callbacks = self.class.ancestors.reverse.each_with_object({}) do |ancestor, hash|
|
151
151
|
SuperCallbacks::Helpers.deep_merge_hashes_and_combine_arrays!(
|
152
152
|
hash,
|
153
153
|
ancestor.instance_variable_get(:@before_callbacks) || {}
|
@@ -183,7 +183,7 @@ module SuperCallbacks
|
|
183
183
|
# TODO: optimize by instead of dynamically getting all_ancestral_after_callbacks on runtime
|
184
184
|
# set them immediately when `include` is called on Base class
|
185
185
|
def run_after_callbacks(method_name, *args)
|
186
|
-
all_ancestral_after_callbacks = self.class.ancestors.each_with_object({}) do |ancestor, hash|
|
186
|
+
all_ancestral_after_callbacks = self.class.ancestors.reverse.each_with_object({}) do |ancestor, hash|
|
187
187
|
SuperCallbacks::Helpers.deep_merge_hashes_and_combine_arrays!(
|
188
188
|
hash,
|
189
189
|
ancestor.instance_variable_get(:@after_callbacks) || {}
|
data/super_callbacks.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler', '~>
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
26
|
spec.add_development_dependency 'byebug', '~> 9.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_callbacks
|
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
|
- Jules Roman B. Polidario
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.16'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,9 +78,9 @@ extra_rdoc_files: []
|
|
78
78
|
files:
|
79
79
|
- ".gitignore"
|
80
80
|
- ".rspec"
|
81
|
+
- ".ruby-version"
|
81
82
|
- ".travis.yml"
|
82
83
|
- Gemfile
|
83
|
-
- Gemfile.lock
|
84
84
|
- LICENSE.txt
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.4.5.1
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Allows `before` and `after` callbacks to any Class. Supports both class and
|
data/Gemfile.lock
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
super_callbacks (1.0.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
byebug (9.1.0)
|
10
|
-
diff-lcs (1.3)
|
11
|
-
rake (10.5.0)
|
12
|
-
rspec (3.8.0)
|
13
|
-
rspec-core (~> 3.8.0)
|
14
|
-
rspec-expectations (~> 3.8.0)
|
15
|
-
rspec-mocks (~> 3.8.0)
|
16
|
-
rspec-core (3.8.2)
|
17
|
-
rspec-support (~> 3.8.0)
|
18
|
-
rspec-expectations (3.8.4)
|
19
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
-
rspec-support (~> 3.8.0)
|
21
|
-
rspec-mocks (3.8.1)
|
22
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.8.0)
|
24
|
-
rspec-support (3.8.2)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
bundler (~> 2.0)
|
31
|
-
byebug (~> 9.0)
|
32
|
-
rake (~> 10.0)
|
33
|
-
rspec (~> 3.0)
|
34
|
-
super_callbacks!
|
35
|
-
|
36
|
-
BUNDLED WITH
|
37
|
-
2.0.2
|