filthy 1.0.1 → 2.0.0
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.md +2 -1
- data/README.rdoc +2 -1
- data/Rakefile +1 -1
- data/filthy.gemspec +2 -2
- data/lib/filthy.rb +13 -11
- data/test/filthy_test.rb +17 -0
- data/test/helper.rb +7 -1
- metadata +61 -93
data/README.md
CHANGED
@@ -10,6 +10,7 @@ gem install filthy
|
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
class Movie < ActiveRecord::Base
|
13
|
+
include Filthy
|
13
14
|
|
14
15
|
filthy_attributes :title, :director
|
15
16
|
|
@@ -31,7 +32,7 @@ end
|
|
31
32
|
|
32
33
|
# Credits
|
33
34
|
|
34
|
-
Filthy is maintained by [Mike Taylor](http://github.com/sealabcore) and is funded by [BookRenter.com](http://www.bookrenter.com "BookRenter.com"). Many of the ideas that have inspired Filthy come from practical usage by the Bookrenter software development team and conversations with Bookrenter developers [Andrew Wheeler](http://github.com/jawheeler), [Michael Pearce](http://github.com/michaelgpearce),
|
35
|
+
Filthy is maintained by [Mike Taylor](http://github.com/sealabcore) and is funded by [BookRenter.com](http://www.bookrenter.com "BookRenter.com"). Many of the ideas that have inspired Filthy come from practical usage by the Bookrenter software development team and conversations with Bookrenter developers [Andrew Wheeler](http://github.com/jawheeler), [Michael Pearce](http://github.com/michaelgpearce), [Philippe Huibonhoa](http://github.com/phuibonhoa), and [Ben Somers](http://github.com/bensomers).
|
35
36
|
|
36
37
|

|
37
38
|
|
data/README.rdoc
CHANGED
@@ -10,6 +10,7 @@ Rails gem to check if an attribute was changed on the last save. Useful in after
|
|
10
10
|
|
11
11
|
|
12
12
|
class Movie < ActiveRecord::Base
|
13
|
+
include Filthy
|
13
14
|
|
14
15
|
filthy_attributes :title, :director
|
15
16
|
|
@@ -35,4 +36,4 @@ Filthy is maintained by Mike Taylor and is funded by BookRenter.com. Many of the
|
|
35
36
|
|
36
37
|
== Copyright
|
37
38
|
|
38
|
-
Copyright (c) 2012 Mike Taylor, Bookrenter.com.
|
39
|
+
Copyright (c) 2012 Mike Taylor, Bookrenter.com.
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('filthy', '
|
5
|
+
Echoe.new('filthy', '2.0.0') do |p|
|
6
6
|
p.description = "Check if an attribute was changed after the last save."
|
7
7
|
p.url = "http://github.com/sealabcore/filthy"
|
8
8
|
p.author = "Mike Taylor"
|
data/filthy.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "filthy"
|
5
|
-
s.version = "
|
5
|
+
s.version = "2.0.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Mike Taylor"]
|
9
|
-
s.date = "2012-
|
9
|
+
s.date = "2012-02-08"
|
10
10
|
s.description = "Check if an attribute was changed after the last save."
|
11
11
|
s.email = "michael.taylor@bookrenter.com"
|
12
12
|
s.extra_rdoc_files = ["README.md", "README.rdoc", "lib/filthy.rb"]
|
data/lib/filthy.rb
CHANGED
@@ -6,11 +6,17 @@ module Filthy
|
|
6
6
|
module ClassMethods
|
7
7
|
|
8
8
|
def filthy_attributes(*args)
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
raise ArgumentError if args.empty?
|
10
|
+
class_inheritable_accessor :filthy_columns, :filthy_attribute_methods
|
11
|
+
|
12
|
+
if self.filthy_columns
|
13
|
+
self.filthy_columns |= args
|
14
|
+
else
|
15
|
+
self.filthy_columns = args
|
16
|
+
end
|
17
|
+
self.filthy_attribute_methods = self.filthy_columns.collect { |attribute| :"#{attribute}_filthy" }
|
12
18
|
|
13
|
-
|
19
|
+
self.filthy_attribute_methods.each do |method|
|
14
20
|
attr_accessor method
|
15
21
|
|
16
22
|
send(:define_method, :"#{method}?") do
|
@@ -23,19 +29,19 @@ module Filthy
|
|
23
29
|
module InstanceMethods
|
24
30
|
|
25
31
|
def has_filthy_attributes?
|
26
|
-
self.
|
32
|
+
defined?(filthy_columns) and self.filthy_columns.present?
|
27
33
|
end
|
28
34
|
|
29
35
|
def set_filthy_before_save
|
30
36
|
clean_filthy_attributes
|
31
|
-
filthy_attributes = changes.keys.select { |attribute| self.class.
|
37
|
+
filthy_attributes = changes.keys.select { |attribute| self.class.filthy_columns.include? attribute.to_sym }
|
32
38
|
filthy_attributes.each do |filthy_attribute|
|
33
39
|
send("#{filthy_attribute}_filthy=", true)
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
43
|
def clean_filthy_attributes
|
38
|
-
self.class.
|
44
|
+
self.class.filthy_attribute_methods.each { |fa| send("#{fa}=", nil) }
|
39
45
|
end
|
40
46
|
|
41
47
|
end
|
@@ -47,7 +53,3 @@ module Filthy
|
|
47
53
|
end
|
48
54
|
|
49
55
|
end
|
50
|
-
|
51
|
-
class ActiveRecord::Base
|
52
|
-
include Filthy
|
53
|
-
end
|
data/test/filthy_test.rb
CHANGED
@@ -7,6 +7,12 @@ class MovieTest < Test::Unit::TestCase
|
|
7
7
|
@movie = Movie.new
|
8
8
|
end
|
9
9
|
|
10
|
+
context "with no arguments" do
|
11
|
+
should "raise an ArgumentError" do
|
12
|
+
assert_raise(ArgumentError) { Movie.filthy_attributes }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
context "with passed attributes" do
|
11
17
|
context "on a new record" do
|
12
18
|
should "create accessors" do
|
@@ -82,7 +88,18 @@ class MovieTest < Test::Unit::TestCase
|
|
82
88
|
assert @short.title_filthy?
|
83
89
|
end
|
84
90
|
end
|
91
|
+
|
92
|
+
context "with a subclass with different filthy_attributes defined" do
|
93
|
+
should "inherit the parent class's filthy attributes and add to them" do
|
94
|
+
assert_same_elements [:best_boy_grip, :title, :director], Documentary.filthy_columns
|
95
|
+
end
|
96
|
+
|
97
|
+
should "not alter the parent class's filthy attributes" do
|
98
|
+
assert_same_elements [:title, :director], Movie.filthy_columns
|
99
|
+
end
|
100
|
+
end
|
85
101
|
end
|
102
|
+
|
86
103
|
|
87
104
|
end
|
88
105
|
|
data/test/helper.rb
CHANGED
@@ -10,6 +10,7 @@ ActiveRecord::Base.establish_connection(config['test'])
|
|
10
10
|
ActiveRecord::Base.connection.create_table :movies, :force => true do |table|
|
11
11
|
table.column :title, :string
|
12
12
|
table.column :director, :string
|
13
|
+
table.column :best_boy_grip, :string
|
13
14
|
end
|
14
15
|
|
15
16
|
ActiveRecord::Base.connection.create_table :actors, :force => true do |table|
|
@@ -18,14 +19,19 @@ ActiveRecord::Base.connection.create_table :actors, :force => true do |table|
|
|
18
19
|
end
|
19
20
|
|
20
21
|
class Movie < ActiveRecord::Base
|
22
|
+
include Filthy
|
21
23
|
|
22
24
|
filthy_attributes :title, :director
|
23
|
-
|
24
25
|
end
|
25
26
|
|
26
27
|
class Short < Movie
|
27
28
|
end
|
28
29
|
|
30
|
+
class Documentary < Movie
|
31
|
+
filthy_attributes :best_boy_grip
|
32
|
+
end
|
33
|
+
|
29
34
|
class Actor < ActiveRecord::Base
|
35
|
+
include Filthy
|
30
36
|
|
31
37
|
end
|
metadata
CHANGED
@@ -1,103 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: filthy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 1.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mike Taylor
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: sqlite3
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70268718749540 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: active_record
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: *70268718749540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: active_record
|
27
|
+
requirement: &70268718748840 !ruby/object:Gem::Requirement
|
38
28
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
46
33
|
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: active_support
|
50
34
|
prerelease: false
|
51
|
-
|
35
|
+
version_requirements: *70268718748840
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: active_support
|
38
|
+
requirement: &70268718748120 !ruby/object:Gem::Requirement
|
52
39
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
60
44
|
type: :development
|
61
|
-
version_requirements: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: test-unit
|
64
45
|
prerelease: false
|
65
|
-
|
46
|
+
version_requirements: *70268718748120
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: test-unit
|
49
|
+
requirement: &70268718747380 !ruby/object:Gem::Requirement
|
66
50
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
74
55
|
type: :development
|
75
|
-
version_requirements: *id004
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: shoulda-context
|
78
56
|
prerelease: false
|
79
|
-
|
57
|
+
version_requirements: *70268718747380
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: shoulda-context
|
60
|
+
requirement: &70268718746660 !ruby/object:Gem::Requirement
|
80
61
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
version: "0"
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
88
66
|
type: :development
|
89
|
-
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70268718746660
|
90
69
|
description: Check if an attribute was changed after the last save.
|
91
70
|
email: michael.taylor@bookrenter.com
|
92
71
|
executables: []
|
93
|
-
|
94
72
|
extensions: []
|
95
|
-
|
96
|
-
extra_rdoc_files:
|
73
|
+
extra_rdoc_files:
|
97
74
|
- README.md
|
98
75
|
- README.rdoc
|
99
76
|
- lib/filthy.rb
|
100
|
-
files:
|
77
|
+
files:
|
101
78
|
- README.md
|
102
79
|
- README.rdoc
|
103
80
|
- Rakefile
|
@@ -109,42 +86,33 @@ files:
|
|
109
86
|
- filthy.gemspec
|
110
87
|
homepage: http://github.com/sealabcore/filthy
|
111
88
|
licenses: []
|
112
|
-
|
113
89
|
post_install_message:
|
114
|
-
rdoc_options:
|
90
|
+
rdoc_options:
|
115
91
|
- --line-numbers
|
116
92
|
- --inline-source
|
117
93
|
- --title
|
118
94
|
- Filthy
|
119
95
|
- --main
|
120
96
|
- README.md
|
121
|
-
require_paths:
|
97
|
+
require_paths:
|
122
98
|
- lib
|
123
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
100
|
none: false
|
125
|
-
requirements:
|
126
|
-
- -
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
|
129
|
-
|
130
|
-
- 0
|
131
|
-
version: "0"
|
132
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
106
|
none: false
|
134
|
-
requirements:
|
135
|
-
- -
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
|
138
|
-
segments:
|
139
|
-
- 1
|
140
|
-
- 2
|
141
|
-
version: "1.2"
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.2'
|
142
111
|
requirements: []
|
143
|
-
|
144
112
|
rubyforge_project: filthy
|
145
113
|
rubygems_version: 1.8.10
|
146
114
|
signing_key:
|
147
115
|
specification_version: 3
|
148
116
|
summary: Check if an attribute was changed after the last save.
|
149
|
-
test_files:
|
117
|
+
test_files:
|
150
118
|
- test/filthy_test.rb
|