super_callbacks 1.1.1 → 1.1.2
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/README.md +3 -3
- data/lib/super_callbacks.rb +2 -2
- data/lib/super_callbacks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fd64d5b5a8b0fb21cbafcc317f899179a7963e8
|
4
|
+
data.tar.gz: 7e4297e1e6fcaf6d3ee7bf9f0a4ca496e441968e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2e56689fd4acb40b21350965389c379a6a8dd6315b0012f148807853dc6500d1f5e9533538ba0870ae054969c9e51b54c4d06056bdcc7fe069e488f67008feb
|
7
|
+
data.tar.gz: db281bec9a46bf31edb20e4d11b833daa1871c061242f9161bea66fd5f085bfb6b1c8e1ceab7228f5011f18f82932757ad1493c4ae64474eeadc53d19b833f05
|
data/README.md
CHANGED
@@ -370,7 +370,7 @@ end
|
|
370
370
|
class Foo
|
371
371
|
include SuperCallbacks
|
372
372
|
|
373
|
-
attr_accessor :bar
|
373
|
+
attr_accessor :bar
|
374
374
|
|
375
375
|
after :bar= do |arg|
|
376
376
|
puts 'original values of all instance attributes:'
|
@@ -401,7 +401,7 @@ foo.bar = 1 # bar is not changed from 1 to 1
|
|
401
401
|
# => 1
|
402
402
|
```
|
403
403
|
|
404
|
-
*Notice above on the second time `foo.bar = 1` is called, "new value" was no longer "puts", because `@bar` didn't change from 1 to 1. You can only use `instance_variables_before_change`, instance_variable_before_change` and `instance_variable_changed?` inside the SuperCallback cycle; otherwise you will get a `"You cannot call this method outside the SuperCallback cycle"` error
|
404
|
+
*Notice above on the second time `foo.bar = 1` is called, "new value" was no longer "puts", because `@bar` didn't change from 1 to 1. You can only use `instance_variables_before_change`, `instance_variable_before_change` and `instance_variable_changed?` inside the SuperCallback cycle; otherwise you will get a `"You cannot call this method outside the SuperCallback cycle"` error.*
|
405
405
|
|
406
406
|
*Above uses `after!`, but works similarly with `before!`*
|
407
407
|
|
@@ -425,7 +425,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
425
425
|
|
426
426
|
## Changelog
|
427
427
|
|
428
|
-
* 1.1.
|
428
|
+
* 1.1.2 (2019-08-14)
|
429
429
|
* [Supported "dirty" checking of instance variable changes](#example-10-dirty-checking-of-instance-variables-changes)
|
430
430
|
* 1.0.3 (2019-08-12)
|
431
431
|
* Cleaner code without explicitly calling `run_callbacks` anymore; done now because of ruby upgrade from 1.9 to 2.0+ which already supports `prepend`
|
data/lib/super_callbacks.rb
CHANGED
@@ -139,14 +139,14 @@ module SuperCallbacks
|
|
139
139
|
def instance_variable_before_change(instance_variable)
|
140
140
|
raise ArgumentError, "#{instance_variable} should be a string that starts with `@`" unless instance_variable.to_s.start_with? '@'
|
141
141
|
raise 'You cannot call this method outside the SuperCallback cycle' if instance_variables_before_change.nil?
|
142
|
-
instance_variables_before_change[instance_variable]
|
142
|
+
instance_variables_before_change[instance_variable.to_sym]
|
143
143
|
end
|
144
144
|
|
145
145
|
def instance_variable_changed?(instance_variable)
|
146
146
|
raise ArgumentError, "#{instance_variable} should be a string that starts with `@`" unless instance_variable.to_s.start_with? '@'
|
147
147
|
raise 'You cannot call this method outside the SuperCallback cycle' if instance_variables_before_change.nil?
|
148
148
|
|
149
|
-
before_change_value = instance_variable_before_change(instance_variable)
|
149
|
+
before_change_value = instance_variable_before_change(instance_variable.to_sym)
|
150
150
|
current_value = instance_variable_get(instance_variable)
|
151
151
|
before_change_value != current_value
|
152
152
|
end
|