pacecar 1.5.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +9 -1
- data/Appraisals +9 -17
- data/Gemfile +1 -1
- data/Gemfile.lock +93 -108
- data/MIT-LICENSE +1 -1
- data/README.md +10 -109
- data/Rakefile +9 -5
- data/TESTING.md +40 -0
- data/gemfiles/rails_4_mysql2_driver.gemfile +8 -0
- data/gemfiles/rails_4_pg_driver.gemfile +8 -0
- data/gemfiles/rails_4_sqlite3_driver.gemfile +8 -0
- data/lib/pacecar.rb +0 -10
- data/lib/pacecar/boolean.rb +8 -20
- data/lib/pacecar/helpers.rb +7 -16
- data/lib/pacecar/limit.rb +9 -9
- data/lib/pacecar/order.rb +9 -9
- data/lib/pacecar/polymorph.rb +5 -5
- data/lib/pacecar/presence.rb +8 -9
- data/lib/pacecar/search.rb +8 -32
- data/lib/pacecar/state.rb +13 -9
- data/lib/pacecar/version.rb +1 -1
- data/pacecar.gemspec +18 -16
- data/spec/boolean_spec.rb +6 -18
- data/spec/dummy/app/models/mammal.rb +1 -1
- data/spec/dummy/app/models/post.rb +2 -2
- data/spec/dummy/app/models/user.rb +1 -6
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +4 -26
- data/spec/dummy/config/boot.rb +3 -9
- data/spec/dummy/config/database.yml +1 -7
- data/spec/dummy/config/environment.rb +2 -2
- data/spec/dummy/config/environments/development.rb +15 -12
- data/spec/dummy/config/environments/production.rb +57 -26
- data/spec/dummy/config/environments/test.rb +16 -15
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +9 -3
- data/spec/dummy/config/initializers/secret_token.rb +7 -2
- data/spec/dummy/config/initializers/session_store.rb +1 -6
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +20 -2
- data/spec/dummy/config/routes.rb +22 -24
- data/spec/factories.rb +2 -2
- data/spec/helpers_spec.rb +18 -26
- data/spec/integration/navigation_spec.rb +4 -5
- data/spec/limit_spec.rb +11 -11
- data/spec/order_spec.rb +8 -8
- data/spec/pacecar_spec.rb +3 -3
- data/spec/polymorph_spec.rb +6 -6
- data/spec/presence_spec.rb +9 -9
- data/spec/search_spec.rb +14 -48
- data/spec/spec_helper.rb +11 -17
- data/spec/state_spec.rb +29 -29
- metadata +76 -70
- data/gemfiles/rails-3.0.11-database-mysql.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-mysql.gemfile.lock +0 -134
- data/gemfiles/rails-3.0.11-database-mysql2.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-mysql2.gemfile.lock +0 -134
- data/gemfiles/rails-3.0.11-database-pg.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-pg.gemfile.lock +0 -134
- data/gemfiles/rails-3.0.11-database-sqlite3-ruby.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-sqlite3-ruby.gemfile.lock +0 -136
- data/gemfiles/rails-3.0.11-database-sqlite3.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-sqlite3.gemfile.lock +0 -134
- data/gemfiles/rails-3.1.3-database-mysql.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-mysql.gemfile.lock +0 -144
- data/gemfiles/rails-3.1.3-database-mysql2.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-mysql2.gemfile.lock +0 -144
- data/gemfiles/rails-3.1.3-database-pg.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-pg.gemfile.lock +0 -144
- data/gemfiles/rails-3.1.3-database-sqlite3-ruby.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-sqlite3-ruby.gemfile.lock +0 -146
- data/gemfiles/rails-3.1.3-database-sqlite3.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-sqlite3.gemfile.lock +0 -144
- data/lib/pacecar/associations.rb +0 -39
- data/lib/pacecar/datetime.rb +0 -91
- data/lib/pacecar/duration.rb +0 -51
- data/lib/pacecar/numeric.rb +0 -29
- data/lib/pacecar/ranking.rb +0 -53
- data/spec/associations_spec.rb +0 -32
- data/spec/datetime_spec.rb +0 -92
- data/spec/duration_spec.rb +0 -22
- data/spec/numeric_spec.rb +0 -43
- data/spec/ranking_spec.rb +0 -63
@@ -1,146 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/mjankowski/Development/opensource/pacecar
|
3
|
-
specs:
|
4
|
-
pacecar (1.5.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
actionmailer (3.1.3)
|
10
|
-
actionpack (= 3.1.3)
|
11
|
-
mail (~> 2.3.0)
|
12
|
-
actionpack (3.1.3)
|
13
|
-
activemodel (= 3.1.3)
|
14
|
-
activesupport (= 3.1.3)
|
15
|
-
builder (~> 3.0.0)
|
16
|
-
erubis (~> 2.7.0)
|
17
|
-
i18n (~> 0.6)
|
18
|
-
rack (~> 1.3.5)
|
19
|
-
rack-cache (~> 1.1)
|
20
|
-
rack-mount (~> 0.8.2)
|
21
|
-
rack-test (~> 0.6.1)
|
22
|
-
sprockets (~> 2.0.3)
|
23
|
-
activemodel (3.1.3)
|
24
|
-
activesupport (= 3.1.3)
|
25
|
-
builder (~> 3.0.0)
|
26
|
-
i18n (~> 0.6)
|
27
|
-
activerecord (3.1.3)
|
28
|
-
activemodel (= 3.1.3)
|
29
|
-
activesupport (= 3.1.3)
|
30
|
-
arel (~> 2.2.1)
|
31
|
-
tzinfo (~> 0.3.29)
|
32
|
-
activeresource (3.1.3)
|
33
|
-
activemodel (= 3.1.3)
|
34
|
-
activesupport (= 3.1.3)
|
35
|
-
activesupport (3.1.3)
|
36
|
-
multi_json (~> 1.0)
|
37
|
-
appraisal (0.4.0)
|
38
|
-
bundler
|
39
|
-
rake
|
40
|
-
arel (2.2.1)
|
41
|
-
builder (3.0.0)
|
42
|
-
capybara (1.1.2)
|
43
|
-
mime-types (>= 1.16)
|
44
|
-
nokogiri (>= 1.3.3)
|
45
|
-
rack (>= 1.0.0)
|
46
|
-
rack-test (>= 0.5.4)
|
47
|
-
selenium-webdriver (~> 2.0)
|
48
|
-
xpath (~> 0.1.4)
|
49
|
-
childprocess (0.2.6)
|
50
|
-
ffi (~> 1.0.6)
|
51
|
-
diff-lcs (1.1.3)
|
52
|
-
erubis (2.7.0)
|
53
|
-
factory_girl (2.3.2)
|
54
|
-
activesupport
|
55
|
-
factory_girl_rails (1.4.0)
|
56
|
-
factory_girl (~> 2.3.0)
|
57
|
-
railties (>= 3.0.0)
|
58
|
-
ffi (1.0.11)
|
59
|
-
hike (1.2.1)
|
60
|
-
i18n (0.6.0)
|
61
|
-
json (1.6.4)
|
62
|
-
mail (2.3.0)
|
63
|
-
i18n (>= 0.4.0)
|
64
|
-
mime-types (~> 1.16)
|
65
|
-
treetop (~> 1.4.8)
|
66
|
-
metaclass (0.0.1)
|
67
|
-
mime-types (1.17.2)
|
68
|
-
mocha (0.10.0)
|
69
|
-
metaclass (~> 0.0.1)
|
70
|
-
multi_json (1.0.4)
|
71
|
-
nokogiri (1.5.0)
|
72
|
-
polyglot (0.3.3)
|
73
|
-
rack (1.3.6)
|
74
|
-
rack-cache (1.1)
|
75
|
-
rack (>= 0.4)
|
76
|
-
rack-mount (0.8.3)
|
77
|
-
rack (>= 1.0.0)
|
78
|
-
rack-ssl (1.3.2)
|
79
|
-
rack
|
80
|
-
rack-test (0.6.1)
|
81
|
-
rack (>= 1.0)
|
82
|
-
rails (3.1.3)
|
83
|
-
actionmailer (= 3.1.3)
|
84
|
-
actionpack (= 3.1.3)
|
85
|
-
activerecord (= 3.1.3)
|
86
|
-
activeresource (= 3.1.3)
|
87
|
-
activesupport (= 3.1.3)
|
88
|
-
bundler (~> 1.0)
|
89
|
-
railties (= 3.1.3)
|
90
|
-
railties (3.1.3)
|
91
|
-
actionpack (= 3.1.3)
|
92
|
-
activesupport (= 3.1.3)
|
93
|
-
rack-ssl (~> 1.3.2)
|
94
|
-
rake (>= 0.8.7)
|
95
|
-
rdoc (~> 3.4)
|
96
|
-
thor (~> 0.14.6)
|
97
|
-
rake (0.9.2.2)
|
98
|
-
rdoc (3.12)
|
99
|
-
json (~> 1.4)
|
100
|
-
rspec (2.8.0)
|
101
|
-
rspec-core (~> 2.8.0)
|
102
|
-
rspec-expectations (~> 2.8.0)
|
103
|
-
rspec-mocks (~> 2.8.0)
|
104
|
-
rspec-core (2.8.0)
|
105
|
-
rspec-expectations (2.8.0)
|
106
|
-
diff-lcs (~> 1.1.2)
|
107
|
-
rspec-mocks (2.8.0)
|
108
|
-
rspec-rails (2.8.1)
|
109
|
-
actionpack (>= 3.0)
|
110
|
-
activesupport (>= 3.0)
|
111
|
-
railties (>= 3.0)
|
112
|
-
rspec (~> 2.8.0)
|
113
|
-
rubyzip (0.9.5)
|
114
|
-
selenium-webdriver (2.16.0)
|
115
|
-
childprocess (>= 0.2.5)
|
116
|
-
ffi (~> 1.0.9)
|
117
|
-
multi_json (~> 1.0.4)
|
118
|
-
rubyzip
|
119
|
-
sprockets (2.0.3)
|
120
|
-
hike (~> 1.2)
|
121
|
-
rack (~> 1.0)
|
122
|
-
tilt (~> 1.1, != 1.3.0)
|
123
|
-
sqlite3 (1.3.5)
|
124
|
-
sqlite3-ruby (1.3.3)
|
125
|
-
sqlite3 (>= 1.3.3)
|
126
|
-
thor (0.14.6)
|
127
|
-
tilt (1.3.3)
|
128
|
-
treetop (1.4.10)
|
129
|
-
polyglot
|
130
|
-
polyglot (>= 0.3.1)
|
131
|
-
tzinfo (0.3.31)
|
132
|
-
xpath (0.1.4)
|
133
|
-
nokogiri (~> 1.3)
|
134
|
-
|
135
|
-
PLATFORMS
|
136
|
-
ruby
|
137
|
-
|
138
|
-
DEPENDENCIES
|
139
|
-
appraisal (~> 0.4)
|
140
|
-
capybara (>= 0.4.0)
|
141
|
-
factory_girl_rails
|
142
|
-
mocha
|
143
|
-
pacecar!
|
144
|
-
rails (= 3.1.3)
|
145
|
-
rspec-rails (>= 2.4.0)
|
146
|
-
sqlite3-ruby
|
@@ -1,144 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/mjankowski/Development/opensource/pacecar
|
3
|
-
specs:
|
4
|
-
pacecar (1.5.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
actionmailer (3.1.3)
|
10
|
-
actionpack (= 3.1.3)
|
11
|
-
mail (~> 2.3.0)
|
12
|
-
actionpack (3.1.3)
|
13
|
-
activemodel (= 3.1.3)
|
14
|
-
activesupport (= 3.1.3)
|
15
|
-
builder (~> 3.0.0)
|
16
|
-
erubis (~> 2.7.0)
|
17
|
-
i18n (~> 0.6)
|
18
|
-
rack (~> 1.3.5)
|
19
|
-
rack-cache (~> 1.1)
|
20
|
-
rack-mount (~> 0.8.2)
|
21
|
-
rack-test (~> 0.6.1)
|
22
|
-
sprockets (~> 2.0.3)
|
23
|
-
activemodel (3.1.3)
|
24
|
-
activesupport (= 3.1.3)
|
25
|
-
builder (~> 3.0.0)
|
26
|
-
i18n (~> 0.6)
|
27
|
-
activerecord (3.1.3)
|
28
|
-
activemodel (= 3.1.3)
|
29
|
-
activesupport (= 3.1.3)
|
30
|
-
arel (~> 2.2.1)
|
31
|
-
tzinfo (~> 0.3.29)
|
32
|
-
activeresource (3.1.3)
|
33
|
-
activemodel (= 3.1.3)
|
34
|
-
activesupport (= 3.1.3)
|
35
|
-
activesupport (3.1.3)
|
36
|
-
multi_json (~> 1.0)
|
37
|
-
appraisal (0.4.0)
|
38
|
-
bundler
|
39
|
-
rake
|
40
|
-
arel (2.2.1)
|
41
|
-
builder (3.0.0)
|
42
|
-
capybara (1.1.2)
|
43
|
-
mime-types (>= 1.16)
|
44
|
-
nokogiri (>= 1.3.3)
|
45
|
-
rack (>= 1.0.0)
|
46
|
-
rack-test (>= 0.5.4)
|
47
|
-
selenium-webdriver (~> 2.0)
|
48
|
-
xpath (~> 0.1.4)
|
49
|
-
childprocess (0.2.6)
|
50
|
-
ffi (~> 1.0.6)
|
51
|
-
diff-lcs (1.1.3)
|
52
|
-
erubis (2.7.0)
|
53
|
-
factory_girl (2.3.2)
|
54
|
-
activesupport
|
55
|
-
factory_girl_rails (1.4.0)
|
56
|
-
factory_girl (~> 2.3.0)
|
57
|
-
railties (>= 3.0.0)
|
58
|
-
ffi (1.0.11)
|
59
|
-
hike (1.2.1)
|
60
|
-
i18n (0.6.0)
|
61
|
-
json (1.6.4)
|
62
|
-
mail (2.3.0)
|
63
|
-
i18n (>= 0.4.0)
|
64
|
-
mime-types (~> 1.16)
|
65
|
-
treetop (~> 1.4.8)
|
66
|
-
metaclass (0.0.1)
|
67
|
-
mime-types (1.17.2)
|
68
|
-
mocha (0.10.0)
|
69
|
-
metaclass (~> 0.0.1)
|
70
|
-
multi_json (1.0.4)
|
71
|
-
nokogiri (1.5.0)
|
72
|
-
polyglot (0.3.3)
|
73
|
-
rack (1.3.6)
|
74
|
-
rack-cache (1.1)
|
75
|
-
rack (>= 0.4)
|
76
|
-
rack-mount (0.8.3)
|
77
|
-
rack (>= 1.0.0)
|
78
|
-
rack-ssl (1.3.2)
|
79
|
-
rack
|
80
|
-
rack-test (0.6.1)
|
81
|
-
rack (>= 1.0)
|
82
|
-
rails (3.1.3)
|
83
|
-
actionmailer (= 3.1.3)
|
84
|
-
actionpack (= 3.1.3)
|
85
|
-
activerecord (= 3.1.3)
|
86
|
-
activeresource (= 3.1.3)
|
87
|
-
activesupport (= 3.1.3)
|
88
|
-
bundler (~> 1.0)
|
89
|
-
railties (= 3.1.3)
|
90
|
-
railties (3.1.3)
|
91
|
-
actionpack (= 3.1.3)
|
92
|
-
activesupport (= 3.1.3)
|
93
|
-
rack-ssl (~> 1.3.2)
|
94
|
-
rake (>= 0.8.7)
|
95
|
-
rdoc (~> 3.4)
|
96
|
-
thor (~> 0.14.6)
|
97
|
-
rake (0.9.2.2)
|
98
|
-
rdoc (3.12)
|
99
|
-
json (~> 1.4)
|
100
|
-
rspec (2.8.0)
|
101
|
-
rspec-core (~> 2.8.0)
|
102
|
-
rspec-expectations (~> 2.8.0)
|
103
|
-
rspec-mocks (~> 2.8.0)
|
104
|
-
rspec-core (2.8.0)
|
105
|
-
rspec-expectations (2.8.0)
|
106
|
-
diff-lcs (~> 1.1.2)
|
107
|
-
rspec-mocks (2.8.0)
|
108
|
-
rspec-rails (2.8.1)
|
109
|
-
actionpack (>= 3.0)
|
110
|
-
activesupport (>= 3.0)
|
111
|
-
railties (>= 3.0)
|
112
|
-
rspec (~> 2.8.0)
|
113
|
-
rubyzip (0.9.5)
|
114
|
-
selenium-webdriver (2.16.0)
|
115
|
-
childprocess (>= 0.2.5)
|
116
|
-
ffi (~> 1.0.9)
|
117
|
-
multi_json (~> 1.0.4)
|
118
|
-
rubyzip
|
119
|
-
sprockets (2.0.3)
|
120
|
-
hike (~> 1.2)
|
121
|
-
rack (~> 1.0)
|
122
|
-
tilt (~> 1.1, != 1.3.0)
|
123
|
-
sqlite3 (1.3.5)
|
124
|
-
thor (0.14.6)
|
125
|
-
tilt (1.3.3)
|
126
|
-
treetop (1.4.10)
|
127
|
-
polyglot
|
128
|
-
polyglot (>= 0.3.1)
|
129
|
-
tzinfo (0.3.31)
|
130
|
-
xpath (0.1.4)
|
131
|
-
nokogiri (~> 1.3)
|
132
|
-
|
133
|
-
PLATFORMS
|
134
|
-
ruby
|
135
|
-
|
136
|
-
DEPENDENCIES
|
137
|
-
appraisal (~> 0.4)
|
138
|
-
capybara (>= 0.4.0)
|
139
|
-
factory_girl_rails
|
140
|
-
mocha
|
141
|
-
pacecar!
|
142
|
-
rails (= 3.1.3)
|
143
|
-
rspec-rails (>= 2.4.0)
|
144
|
-
sqlite3
|
data/lib/pacecar/associations.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Pacecar
|
2
|
-
module Associations
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
|
9
|
-
def has_recent_records(*names)
|
10
|
-
names.each do |name|
|
11
|
-
scope "recent_#{name}_since".to_sym, lambda { |since|
|
12
|
-
{
|
13
|
-
:conditions => [conditions_for_name(name), { :since_time => since }]
|
14
|
-
}
|
15
|
-
}
|
16
|
-
end
|
17
|
-
unless names.first == names.last
|
18
|
-
scope "recent_#{names.join('_or_')}_since".to_sym, lambda { |since|
|
19
|
-
{
|
20
|
-
:conditions => [names.collect { |name| conditions_for_name(name) }.join(' or '), { :since_time => since }]
|
21
|
-
}
|
22
|
-
}
|
23
|
-
scope "recent_#{names.join('_and_')}_since".to_sym, lambda { |since|
|
24
|
-
{
|
25
|
-
:conditions => [names.collect { |name| conditions_for_name(name) }.join(' and '), { :since_time => since }]
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def conditions_for_name(name)
|
34
|
-
"((select count(*) from #{connection.quote_table_name(name)} where #{connection.quote_table_name(name)}.#{connection.quote_column_name(reflections[name].respond_to?(:foreign_key) ? reflections[name].foreign_key : reflections[name].primary_key_name)} = #{quoted_table_name}.#{connection.quote_column_name primary_key} and #{connection.quote_table_name(name)}.#{connection.quote_column_name("created_at")} > :since_time) > 0)"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/pacecar/datetime.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
module Pacecar
|
2
|
-
module Datetime
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def self.extended(base)
|
9
|
-
base.send :define_datetime_scopes
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def define_datetime_scopes
|
15
|
-
datetime_column_names.each do |name|
|
16
|
-
define_before_after_scopes(name)
|
17
|
-
define_past_future_scopes(name)
|
18
|
-
define_inside_outside_scopes(name)
|
19
|
-
define_in_date_scopes(name)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def define_before_after_scopes(name)
|
24
|
-
scope "#{name}_before".to_sym, lambda { |time|
|
25
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} <= ?", time] }
|
26
|
-
}
|
27
|
-
scope "#{name}_after".to_sym, lambda { |time|
|
28
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} >= ?", time] }
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def define_past_future_scopes(name)
|
33
|
-
scope "#{name}_in_past", lambda {
|
34
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} <= ?", now] }
|
35
|
-
}
|
36
|
-
scope "#{name}_in_future", lambda {
|
37
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} >= ?", now] }
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def define_inside_outside_scopes(name)
|
42
|
-
scope "#{name}_inside".to_sym, lambda { |start, stop|
|
43
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} >= ? and #{quoted_table_name}.#{connection.quote_column_name name} <= ?", start, stop] }
|
44
|
-
}
|
45
|
-
scope "#{name}_outside".to_sym, lambda { |start, stop|
|
46
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} <= ? or #{quoted_table_name}.#{connection.quote_column_name name} >= ?", start, stop] }
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
def define_in_date_scopes(name)
|
51
|
-
case connection.adapter_name
|
52
|
-
when 'MySQL', 'Mysql2'
|
53
|
-
scope "#{name}_in_year".to_sym, lambda { |year|
|
54
|
-
{ :conditions => ["year(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", year.to_i] }
|
55
|
-
}
|
56
|
-
scope "#{name}_in_month".to_sym, lambda { |month|
|
57
|
-
{ :conditions => ["month(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", month.to_i] }
|
58
|
-
}
|
59
|
-
scope "#{name}_in_day".to_sym, lambda { |day|
|
60
|
-
{ :conditions => ["day(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", day.to_i] }
|
61
|
-
}
|
62
|
-
when 'PostgreSQL'
|
63
|
-
scope "#{name}_in_year".to_sym, lambda { |year|
|
64
|
-
{ :conditions => ["extract(year from #{quoted_table_name}.#{connection.quote_column_name name}) = ?", year.to_i] }
|
65
|
-
}
|
66
|
-
scope "#{name}_in_month".to_sym, lambda { |month|
|
67
|
-
{ :conditions => ["extract(month from #{quoted_table_name}.#{connection.quote_column_name name}) = ?", month.to_i] }
|
68
|
-
}
|
69
|
-
scope "#{name}_in_day".to_sym, lambda { |day|
|
70
|
-
{ :conditions => ["extract(day from #{quoted_table_name}.#{connection.quote_column_name name}) = ?", day.to_i] }
|
71
|
-
}
|
72
|
-
when 'SQLite'
|
73
|
-
scope "#{name}_in_year".to_sym, lambda { |year|
|
74
|
-
{ :conditions => ["strftime('%Y', #{quoted_table_name}.#{connection.quote_column_name name}) = ?", sprintf('%04d', year)] }
|
75
|
-
}
|
76
|
-
scope "#{name}_in_month".to_sym, lambda { |month|
|
77
|
-
{ :conditions => ["strftime('%m', #{quoted_table_name}.#{connection.quote_column_name name}) = ?", sprintf('%02d', month)] }
|
78
|
-
}
|
79
|
-
scope "#{name}_in_day".to_sym, lambda { |day|
|
80
|
-
{ :conditions => ["strftime('%d', #{quoted_table_name}.#{connection.quote_column_name name}) = ?", sprintf('%02d', day)] }
|
81
|
-
}
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def now
|
86
|
-
defined?(Time.zone_default) && Time.zone_default ? Time.zone_default.now : Time.now
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/lib/pacecar/duration.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
module Pacecar
|
2
|
-
module Duration
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def self.extended(base)
|
9
|
-
base.send :define_duration_scopes
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def define_duration_scopes
|
15
|
-
case connection.adapter_name
|
16
|
-
when 'MySQL', 'Mysql2'
|
17
|
-
scope :with_duration_of, lambda { |duration, start, stop|
|
18
|
-
{ :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) = ?", duration] }
|
19
|
-
}
|
20
|
-
scope :with_duration_over, lambda { |duration, start, stop|
|
21
|
-
{ :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) > ?", duration] }
|
22
|
-
}
|
23
|
-
scope :with_duration_under, lambda { |duration, start, stop|
|
24
|
-
{ :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) < ?", duration] }
|
25
|
-
}
|
26
|
-
when 'PostgreSQL'
|
27
|
-
scope :with_duration_of, lambda { |duration, start, stop|
|
28
|
-
{ :conditions => ["age(#{quoted_table_name}.#{connection.quote_column_name stop}, #{quoted_table_name}.#{connection.quote_column_name start}) = '? days'", duration] }
|
29
|
-
}
|
30
|
-
scope :with_duration_over, lambda { |duration, start, stop|
|
31
|
-
{ :conditions => ["age(#{quoted_table_name}.#{connection.quote_column_name stop}, #{quoted_table_name}.#{connection.quote_column_name start}) > interval '? days'", duration] }
|
32
|
-
}
|
33
|
-
scope :with_duration_under, lambda { |duration, start, stop|
|
34
|
-
{ :conditions => ["age(#{quoted_table_name}.#{connection.quote_column_name stop}, #{quoted_table_name}.#{connection.quote_column_name start}) < interval '? days'", duration] }
|
35
|
-
}
|
36
|
-
when 'SQLite'
|
37
|
-
scope :with_duration_of, lambda { |duration, start, stop|
|
38
|
-
{ :conditions => ["abs(julianday(#{quoted_table_name}.#{connection.quote_column_name start}) - julianday(#{quoted_table_name}.#{connection.quote_column_name stop})) = ?", duration] }
|
39
|
-
}
|
40
|
-
scope :with_duration_over, lambda { |duration, start, stop|
|
41
|
-
{ :conditions => ["abs(julianday(#{quoted_table_name}.#{connection.quote_column_name start}) - julianday(#{quoted_table_name}.#{connection.quote_column_name stop})) > ?", duration] }
|
42
|
-
}
|
43
|
-
scope :with_duration_under, lambda { |duration, start, stop|
|
44
|
-
{ :conditions => ["abs(julianday(#{quoted_table_name}.#{connection.quote_column_name start}) - julianday(#{quoted_table_name}.#{connection.quote_column_name stop})) < ?", duration] }
|
45
|
-
}
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|