thoughtbot-pacecar 1.0.2 → 1.1.2
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.rdoc +19 -5
- data/lib/pacecar/polymorph.rb +1 -1
- data/lib/pacecar/ranking.rb +1 -1
- data/lib/pacecar/state.rb +9 -1
- data/lib/pacecar.rb +11 -28
- metadata +2 -2
data/README.rdoc
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
== Pacecar
|
|
2
2
|
|
|
3
|
-
Pacecar adds named_scope methods to ActiveRecord classes via database column introspection.
|
|
3
|
+
Pacecar adds named_scope methods and other common functionality to ActiveRecord classes via database column introspection.
|
|
4
|
+
|
|
5
|
+
Pacecar automatically includes the Pacecar::Helpers module into all ActiveRecord::Base classes.
|
|
6
|
+
|
|
7
|
+
To get all Pacecar functionality, you need to "include Pacecar" in your class.
|
|
8
|
+
|
|
9
|
+
To get some subset (for example, only the state functionality), you can do something like "include Pacecar::State" to get only the module(s) you want.
|
|
4
10
|
|
|
5
11
|
== Usage
|
|
6
12
|
|
|
@@ -35,21 +41,24 @@ Assuming a database schema...
|
|
|
35
41
|
And some basic model declarations...
|
|
36
42
|
|
|
37
43
|
class User < ActiveRecord::Base
|
|
44
|
+
include Pacecar
|
|
38
45
|
has_many :posts, :as => :owner
|
|
39
46
|
has_many :comments
|
|
40
|
-
|
|
47
|
+
has_ranking :comments
|
|
41
48
|
end
|
|
42
49
|
|
|
43
50
|
class Post < ActiveRecord::Base
|
|
51
|
+
include Pacecar
|
|
44
52
|
PUBLICATION_STATES = %w(Draft Submitted Rejected Accepted)
|
|
45
53
|
TYPES = %w(Free Open Private Anonymous PostModern)
|
|
46
54
|
belongs_to :owner, :polymorphic => true
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
has_state :publication_state
|
|
56
|
+
has_state :post_type, :with => TYPES
|
|
57
|
+
has_polymorph :owner
|
|
50
58
|
end
|
|
51
59
|
|
|
52
60
|
class Comment < ActiveRecord::Base
|
|
61
|
+
include Pacecar
|
|
53
62
|
belongs_to :user
|
|
54
63
|
end
|
|
55
64
|
|
|
@@ -148,6 +157,11 @@ Records which are in a particular state, or not in a state...
|
|
|
148
157
|
Post.publication_state_draft
|
|
149
158
|
Post.post_type_not_open
|
|
150
159
|
|
|
160
|
+
Query methods on instances to check state...
|
|
161
|
+
|
|
162
|
+
Post.first.publication_state_draft?
|
|
163
|
+
Post.last.post_type_not_open?
|
|
164
|
+
|
|
151
165
|
= Limits
|
|
152
166
|
|
|
153
167
|
First x records...
|
data/lib/pacecar/polymorph.rb
CHANGED
data/lib/pacecar/ranking.rb
CHANGED
data/lib/pacecar/state.rb
CHANGED
|
@@ -6,13 +6,21 @@ module Pacecar
|
|
|
6
6
|
|
|
7
7
|
module ClassMethods
|
|
8
8
|
|
|
9
|
-
def
|
|
9
|
+
def has_state(*names)
|
|
10
10
|
opts = names.extract_options!
|
|
11
11
|
names.each do |name|
|
|
12
12
|
constant = opts[:with] || const_get(name.to_s.pluralize.upcase)
|
|
13
13
|
constant.each do |state|
|
|
14
14
|
named_scope "#{name}_#{state.downcase}".to_sym, :conditions => ["#{quoted_table_name}.#{name} = ?", state]
|
|
15
15
|
named_scope "#{name}_not_#{state.downcase}".to_sym, :conditions => ["#{quoted_table_name}.#{name} <> ?", state]
|
|
16
|
+
self.class_eval %Q{
|
|
17
|
+
def #{name}_#{state.downcase}?
|
|
18
|
+
#{name} == '#{state}'
|
|
19
|
+
end
|
|
20
|
+
def #{name}_not_#{state.downcase}?
|
|
21
|
+
#{name} != '#{state}'
|
|
22
|
+
end
|
|
23
|
+
}
|
|
16
24
|
end
|
|
17
25
|
end
|
|
18
26
|
end
|
data/lib/pacecar.rb
CHANGED
|
@@ -13,35 +13,18 @@ require 'pacecar/state'
|
|
|
13
13
|
module Pacecar
|
|
14
14
|
def self.included(base)
|
|
15
15
|
base.class_eval do
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
include Pacecar::Boolean
|
|
17
|
+
include Pacecar::Datetime
|
|
18
|
+
include Pacecar::Duration
|
|
19
|
+
include Pacecar::Limit
|
|
20
|
+
include Pacecar::Order
|
|
21
|
+
include Pacecar::Polymorph
|
|
22
|
+
include Pacecar::Presence
|
|
23
|
+
include Pacecar::Ranking
|
|
24
|
+
include Pacecar::Search
|
|
25
|
+
include Pacecar::State
|
|
20
26
|
end
|
|
21
27
|
end
|
|
22
|
-
|
|
23
|
-
module ClassMethods
|
|
24
|
-
|
|
25
|
-
protected
|
|
26
|
-
|
|
27
|
-
def inherited_with_define_scopes(child)
|
|
28
|
-
inherited_without_define_scopes(child)
|
|
29
|
-
child.class_eval do
|
|
30
|
-
include Pacecar::Helpers
|
|
31
|
-
include Pacecar::Boolean
|
|
32
|
-
include Pacecar::Datetime
|
|
33
|
-
include Pacecar::Duration
|
|
34
|
-
include Pacecar::Limit
|
|
35
|
-
include Pacecar::Order
|
|
36
|
-
include Pacecar::Polymorph
|
|
37
|
-
include Pacecar::Presence
|
|
38
|
-
include Pacecar::Ranking
|
|
39
|
-
include Pacecar::Search
|
|
40
|
-
include Pacecar::State
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
28
|
end
|
|
46
29
|
|
|
47
|
-
ActiveRecord::Base.send :include, Pacecar
|
|
30
|
+
ActiveRecord::Base.send :include, Pacecar::Helpers
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thoughtbot-pacecar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Jankowski
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date:
|
|
12
|
+
date: 2009-03-23 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|