update_filter 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +13 -0
- data/Rakefile +1 -0
- data/lib/update_filter.rb +41 -0
- data/lib/update_filter/version.rb +3 -0
- data/update_filter.gemspec +25 -0
- metadata +52 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
This gem provides before_update_filter and after_update_filter method for active record class
|
2
|
+
|
3
|
+
Syntax :
|
4
|
+
|
5
|
+
before_update_filter :callback_method, :or_params => [:attr1, :attr2], :and_params = > [:attr3, :attr4]
|
6
|
+
|
7
|
+
after_update_filter :callback_method, :or_params => [:attr1, :attr2], :and_params = > [:attr3, :attr4]
|
8
|
+
|
9
|
+
or_params and and_params are optional.
|
10
|
+
|
11
|
+
If any of or_params attribute is updated then then callabck method will be called.
|
12
|
+
|
13
|
+
If all attributes of and_params is updated only then callback method will be called .
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
def self.before_update_filter(callback_method, options = {})
|
4
|
+
|
5
|
+
self.set_callback :save, :before do
|
6
|
+
|
7
|
+
if options[:or_params].nil? && options[:and_params].nil?
|
8
|
+
send callback_method
|
9
|
+
elsif !options[:or_params].nil? && options[:and_params].nil?
|
10
|
+
send callback_method if options[:or_params].map{ |attr| attribute_changed?(attr.to_s) }.any?
|
11
|
+
elsif options[:or_params].nil? && !options[:and_params].nil?
|
12
|
+
send callback_method if options[:and_params].map{ |attr| attribute_changed?(attr.to_s) }.all?
|
13
|
+
else
|
14
|
+
send callback_method if options[:and_params].map{ |attr| attribute_changed?(attr.to_s) }.all? || options[:or_params].map{ |attr| attribute_changed?(attr.to_s) }.any?
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.after_update_filter(callback_method, options = {})
|
22
|
+
|
23
|
+
|
24
|
+
self.set_callback :save, :after do
|
25
|
+
|
26
|
+
if options[:or_params].nil? && options[:and_params].nil?
|
27
|
+
send callback_method
|
28
|
+
elsif !options[:or_params].nil? && options[:and_params].nil?
|
29
|
+
send callback_method if options[:or_params].map{ |attr| attribute_changed?(attr.to_s) }.any?
|
30
|
+
elsif options[:or_params].nil? && !options[:and_params].nil?
|
31
|
+
send callback_method if options[:and_params].map{ |attr| attribute_changed?(attr.to_s) }.all?
|
32
|
+
else
|
33
|
+
send callback_method if options[:and_params].map{ |attr| attribute_changed?(attr.to_s) }.all? || options[:or_params].map{ |attr| attribute_changed?(attr.to_s) }.any?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
$:.push File.dirname(__FILE__) + '/lib'
|
4
|
+
require "update_filter/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "update_filter"
|
8
|
+
s.version = UpdateFilter::VERSION
|
9
|
+
s.authors = ["Rohit Trivedi"]
|
10
|
+
s.email = ["86.rohit@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Provide update filter hook methods for ActiveRecord class}
|
13
|
+
s.description = %q{Provide mthods before_update_filter and after_update_filter}
|
14
|
+
|
15
|
+
s.rubyforge_project = "update_filter"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# specify any dependencies here; for example:
|
23
|
+
# s.add_development_dependency "rspec"
|
24
|
+
# s.add_runtime_dependency "rest-client"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: update_filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rohit Trivedi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-01 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Provide mthods before_update_filter and after_update_filter
|
15
|
+
email:
|
16
|
+
- 86.rohit@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README
|
24
|
+
- Rakefile
|
25
|
+
- lib/update_filter.rb
|
26
|
+
- lib/update_filter/version.rb
|
27
|
+
- update_filter.gemspec
|
28
|
+
homepage: ''
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: update_filter
|
48
|
+
rubygems_version: 1.8.10
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Provide update filter hook methods for ActiveRecord class
|
52
|
+
test_files: []
|