good_touch 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +35 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +21 -0
- data/Rakefile +1 -45
- data/good_touch.gemspec +19 -49
- data/good_touch.sqlite3 +0 -0
- data/lib/good_touch.rb +12 -2
- data/lib/good_touch/version.rb +3 -0
- data/test/test_good_touch.rb +25 -0
- metadata +55 -17
- data/VERSION +0 -1
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
Gemfile.lock
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
# test files
|
19
|
+
test/*.log
|
20
|
+
test/*.sqlite3
|
21
|
+
|
22
|
+
# For vim:
|
23
|
+
*.swp
|
24
|
+
|
25
|
+
# For MacOS:
|
26
|
+
.DS_Store
|
27
|
+
|
28
|
+
# git files
|
29
|
+
*.orig
|
30
|
+
|
31
|
+
# rails files
|
32
|
+
tmp
|
33
|
+
log
|
34
|
+
*.log
|
35
|
+
*.sqlite3
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ree-1.8.7-2011.03@good_touch --create
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= good_touch
|
2
|
+
|
3
|
+
Update ActiveRecord timestamps without triggering callbacks.
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
|
7
|
+
available on gemcutter:
|
8
|
+
http://rubygems.org/gems/good_touch
|
9
|
+
|
10
|
+
== Note on Patches/Pull Requests
|
11
|
+
|
12
|
+
* Fork the project.
|
13
|
+
* Make your feature addition or bug fix.
|
14
|
+
* Add tests for it. This is important so I don't break it in a
|
15
|
+
future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
17
|
+
* Send me a pull request. Bonus points for topic branches.
|
18
|
+
|
19
|
+
== Copyright
|
20
|
+
|
21
|
+
Copyright (c) 2010 Ryan Sonnek. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,22 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "good_touch"
|
8
|
-
gem.summary = %Q{ Rails 'touch' method without all the overhead}
|
9
|
-
gem.description = %Q{ Update your timestamp attributes without invoking all ActiveRecord callbacks}
|
10
|
-
gem.email = "ryan@codecrate.com"
|
11
|
-
gem.homepage = "http://github.com/wireframe/good_touch"
|
12
|
-
gem.authors = ["Ryan Sonnek"]
|
13
|
-
gem.add_dependency "activerecord", ">= 2.1.0"
|
14
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
20
2
|
|
21
3
|
require 'rake/testtask'
|
22
4
|
Rake::TestTask.new(:test) do |test|
|
@@ -24,30 +6,4 @@ Rake::TestTask.new(:test) do |test|
|
|
24
6
|
test.pattern = 'test/**/test_*.rb'
|
25
7
|
test.verbose = true
|
26
8
|
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task :test => :check_dependencies
|
42
|
-
|
43
9
|
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "good_touch #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
data/good_touch.gemspec
CHANGED
@@ -1,56 +1,26 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "good_touch/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = "good_touch"
|
7
|
+
s.version = GoodTouch::VERSION
|
8
|
+
s.authors = ["Ryan Sonnek"]
|
9
|
+
s.email = ["ryan@codecrate.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Update your timestamp attributes without invoking all ActiveRecord callbacks}
|
12
|
+
s.description = %q{Fix default rails behavior that fires callbacks when touching records}
|
9
13
|
|
10
|
-
s.
|
11
|
-
s.authors = [%q{Ryan Sonnek}]
|
12
|
-
s.date = %q{2011-08-11}
|
13
|
-
s.description = %q{ Update your timestamp attributes without invoking all ActiveRecord callbacks}
|
14
|
-
s.email = %q{ryan@codecrate.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"good_touch.gemspec",
|
26
|
-
"good_touch.sqlite3",
|
27
|
-
"lib/good_touch.rb",
|
28
|
-
"test/database.yml",
|
29
|
-
"test/helper.rb",
|
30
|
-
"test/test_good_touch.rb"
|
31
|
-
]
|
32
|
-
s.homepage = %q{http://github.com/wireframe/good_touch}
|
33
|
-
s.require_paths = [%q{lib}]
|
34
|
-
s.rubygems_version = %q{1.8.5}
|
35
|
-
s.summary = %q{Rails 'touch' method without all the overhead}
|
36
|
-
s.test_files = [
|
37
|
-
"test/helper.rb",
|
38
|
-
"test/test_good_touch.rb"
|
39
|
-
]
|
14
|
+
s.rubyforge_project = "good_touch"
|
40
15
|
|
41
|
-
|
42
|
-
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
43
20
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
-
end
|
51
|
-
else
|
52
|
-
s.add_dependency(%q<activerecord>, [">= 2.1.0"])
|
53
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
-
end
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.1.0"])
|
23
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
24
|
+
s.add_development_dependency(%q<rake>, [">= 0.9.2.2"])
|
25
|
+
s.add_development_dependency(%q<sqlite3>, ['= 1.3.4'])
|
55
26
|
end
|
56
|
-
|
data/good_touch.sqlite3
CHANGED
Binary file
|
data/lib/good_touch.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
+
require "good_touch/version"
|
2
|
+
|
1
3
|
module GoodTouch
|
2
4
|
module InstanceMethods
|
3
5
|
#touch a record without triggering callbacks
|
4
6
|
#update DB directly to avoid overhead of reindexing the user
|
5
|
-
def good_touch(
|
6
|
-
|
7
|
+
def good_touch(*args)
|
8
|
+
value=args.pop unless args.empty?
|
9
|
+
if value.kind_of? Symbol
|
10
|
+
args << value
|
11
|
+
value=Time.now.utc
|
12
|
+
end
|
13
|
+
args << :updated_at if args.empty?
|
14
|
+
updates={}
|
15
|
+
args.each { |arg| updates[arg]=value }
|
16
|
+
self.class.update_all(updates, {:id => self.id})
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
data/test/test_good_touch.rb
CHANGED
@@ -36,6 +36,18 @@ class TestGoodTouch < Test::Unit::TestCase
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
context "calling good_touch with both posted_at and updated_at attributes" do
|
40
|
+
setup do
|
41
|
+
@post.good_touch :posted_at, :updated_at
|
42
|
+
end
|
43
|
+
should_change "posted_at timestamp", :to => @now do
|
44
|
+
@post.reload.posted_at
|
45
|
+
end
|
46
|
+
should_change "updated_at timestamp", :to => @now do
|
47
|
+
@post.reload.updated_at
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
39
51
|
context "calling good_touch with a value" do
|
40
52
|
setup do
|
41
53
|
@time = Date.parse("01/01/2010 12:00")
|
@@ -45,5 +57,18 @@ class TestGoodTouch < Test::Unit::TestCase
|
|
45
57
|
@post.reload.updated_at
|
46
58
|
end
|
47
59
|
end
|
60
|
+
|
61
|
+
context "calling good_touch with both posted_at and updated_at and a value" do
|
62
|
+
setup do
|
63
|
+
@time = Date.parse("01/01/2010 12:00")
|
64
|
+
@post.good_touch :updated_at, :posted_at, @time
|
65
|
+
end
|
66
|
+
should_change "updated_at timestamp", :to => @time do
|
67
|
+
@post.reload.updated_at
|
68
|
+
end
|
69
|
+
should_change "posted_at timestamp", :to => @time do
|
70
|
+
@post.reload.posted_at
|
71
|
+
end
|
72
|
+
end
|
48
73
|
end
|
49
74
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: good_touch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,12 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
22
22
|
prerelease: false
|
23
|
-
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
@@ -31,12 +31,12 @@ dependencies:
|
|
31
31
|
- 1
|
32
32
|
- 0
|
33
33
|
version: 2.1.0
|
34
|
+
requirement: *id001
|
34
35
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: thoughtbot-shoulda
|
38
38
|
prerelease: false
|
39
|
-
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
@@ -45,30 +45,67 @@ dependencies:
|
|
45
45
|
segments:
|
46
46
|
- 0
|
47
47
|
version: "0"
|
48
|
+
requirement: *id002
|
48
49
|
type: :development
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rake
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 11
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
- 9
|
62
|
+
- 2
|
63
|
+
- 2
|
64
|
+
version: 0.9.2.2
|
65
|
+
requirement: *id003
|
66
|
+
type: :development
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: sqlite3
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - "="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 19
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 3
|
79
|
+
- 4
|
80
|
+
version: 1.3.4
|
81
|
+
requirement: *id004
|
82
|
+
type: :development
|
83
|
+
description: Fix default rails behavior that fires callbacks when touching records
|
84
|
+
email:
|
85
|
+
- ryan@codecrate.com
|
52
86
|
executables: []
|
53
87
|
|
54
88
|
extensions: []
|
55
89
|
|
56
|
-
extra_rdoc_files:
|
57
|
-
|
58
|
-
- README.rdoc
|
90
|
+
extra_rdoc_files: []
|
91
|
+
|
59
92
|
files:
|
60
93
|
- .document
|
94
|
+
- .gitignore
|
95
|
+
- .rvmrc
|
96
|
+
- Gemfile
|
61
97
|
- LICENSE
|
98
|
+
- README.md
|
62
99
|
- README.rdoc
|
63
100
|
- Rakefile
|
64
|
-
- VERSION
|
65
101
|
- good_touch.gemspec
|
66
102
|
- good_touch.sqlite3
|
67
103
|
- lib/good_touch.rb
|
104
|
+
- lib/good_touch/version.rb
|
68
105
|
- test/database.yml
|
69
106
|
- test/helper.rb
|
70
107
|
- test/test_good_touch.rb
|
71
|
-
homepage:
|
108
|
+
homepage: ""
|
72
109
|
licenses: []
|
73
110
|
|
74
111
|
post_install_message:
|
@@ -96,11 +133,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
133
|
version: "0"
|
97
134
|
requirements: []
|
98
135
|
|
99
|
-
rubyforge_project:
|
136
|
+
rubyforge_project: good_touch
|
100
137
|
rubygems_version: 1.8.5
|
101
138
|
signing_key:
|
102
139
|
specification_version: 3
|
103
|
-
summary:
|
140
|
+
summary: Update your timestamp attributes without invoking all ActiveRecord callbacks
|
104
141
|
test_files:
|
142
|
+
- test/database.yml
|
105
143
|
- test/helper.rb
|
106
144
|
- test/test_good_touch.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.0
|