acts_as_callbackable 0.2.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.
- data/README +9 -0
- data/lib/acts_as_callbackable.rb +25 -0
- metadata +48 -0
data/README
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= Acts as Callbackable
|
2
|
+
|
3
|
+
This gem makes it easy to call specific methods when targeted attributes are changed in an ActiveRecord model.
|
4
|
+
Simply call acts_as_callbackable within the model class, and then define callback methods with the following format:
|
5
|
+
def on_<attribute>_changed(payload)
|
6
|
+
# Do something
|
7
|
+
end
|
8
|
+
|
9
|
+
The payload argument is the previous value of the attribute.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActsAsCallbackable
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def acts_as_callbackable
|
9
|
+
before_save :update_callbacks
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def update_callbacks
|
15
|
+
self.changed_attributes.each do |k, v|
|
16
|
+
method_name = "on_#{k}_changed"
|
17
|
+
self.send(method_name, v) if self.respond_to? method_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class ActiveRecord::Base
|
24
|
+
include ActsAsCallbackable
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_callbackable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- elhu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-12 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: ActsAsCallbackable provides a single way of calling specific methods
|
15
|
+
when targeted model attributes are modified.
|
16
|
+
email: boisard.v@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README
|
22
|
+
- lib/acts_as_callbackable.rb
|
23
|
+
homepage: http://chugulu.com
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.10
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: ActsAsCallbackable provides a single way of calling specific methods when
|
47
|
+
targeted model attributes are modified.
|
48
|
+
test_files: []
|