aws_onchange 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +22 -0
  3. data/Rakefile +28 -0
  4. data/init.rb +1 -0
  5. data/lib/aws_onchange.rb +41 -0
  6. metadata +71 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,22 @@
1
+ AwsOnchange
2
+ ===========
3
+
4
+ v 1.0 - November 2010
5
+ Add-on to use check easily change on some model, and running action
6
+
7
+ see wiki for more detailled information : http://wiki.github.com/supernini/aws_onchange/
8
+
9
+
10
+
11
+ Example
12
+ =======
13
+
14
+ #each time, field1 and field3 are change or created, update_action is called
15
+ class MyModels < ActiveRecord::Base
16
+ my_cache_update :checked_field => [:field1, :field3], :method => :update_action, :oncreate => true
17
+
18
+ def update_action
19
+ #action to do
20
+ end
21
+ end
22
+
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/packagetask'
7
+ require 'rake/gempackagetask'
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = "aws_onchange"
11
+ s.version = "0.0.1"
12
+ s.author = "Denis FABIEN"
13
+ s.email = "denis@miseajour.net"
14
+ s.homepage = "https://github.com/supernini/aws_onchange"
15
+ s.platform = Gem::Platform::RUBY
16
+ s.summary = "Check easily change on models, and run action"
17
+ s.files = FileList[
18
+ '[a-zA-Z]*',
19
+ 'lib/**/*']
20
+ s.require_path = "lib"
21
+ s.has_rdoc = false
22
+ s.extra_rdoc_files = ["README"]
23
+ end
24
+
25
+ desc 'Turn this plugin into a gem.'
26
+ Rake::GemPackageTask.new(spec) do |pkg|
27
+ pkg.gem_spec = spec
28
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'aws_onchange'
@@ -0,0 +1,41 @@
1
+ module ActiveRecord
2
+ class Base
3
+ after_save :aws_check_each_field
4
+ after_create :aws_check_create
5
+
6
+ def self.aws_onchange(*args)
7
+ options = args.extract_options!
8
+ #dbug(options[:checked_field])
9
+
10
+ cattr_accessor :aws_onchange_field
11
+ cattr_accessor :aws_onchange_method
12
+ cattr_accessor :aws_onchange_oncreate
13
+
14
+ self.aws_onchange_field = (options[:checked_field] and options[:checked_field].respond_to?('each')?options[:checked_field]:[options])
15
+ self.aws_onchange_method = (options[:method]?options[:method]:'update_cache')
16
+ self.aws_onchange_oncreate = (options[:oncreate]?options[:oncreate]:false)
17
+ end
18
+
19
+ private
20
+ def aws_check_create
21
+ if self.aws_onchange_oncreate==true
22
+ self.send(self.aws_onchange_method)
23
+ end
24
+ end
25
+
26
+ def aws_check_each_field
27
+ if self.respond_to?('aws_onchange_field')
28
+ puts self.aws_onchange_oncreate
29
+ need_update = false
30
+ self.aws_onchange_field.each do |item|
31
+ if item!='' and self.changed.include?(item.to_s)
32
+ need_update = true
33
+ end
34
+ end
35
+ if need_update
36
+ self.send(self.aws_onchange_method)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_onchange
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Denis FABIEN
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-29 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: denis@miseajour.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - init.rb
32
+ - MIT-LICENSE
33
+ - Rakefile
34
+ - README
35
+ - lib/aws_onchange.rb
36
+ has_rdoc: true
37
+ homepage: https://github.com/supernini/aws_onchange
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Check easily change on models, and run action
70
+ test_files: []
71
+