restful_query 0.3.1 → 0.3.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/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.2 2011-04-23
2
+
3
+ * Support for Rails 3 and Ruby 1.9.2
4
+
1
5
  == 0.3.1 2010-02-16
2
6
 
3
7
  * Parser takes a :map_columns option which maps aliases column names
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), 'rails', 'init.rb')
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'rails', 'init.rb')
@@ -1,6 +1,6 @@
1
1
  module RestfulQuery
2
2
  module CanQuery
3
-
3
+
4
4
  def self.included(klass)
5
5
  klass.extend MacroMethods
6
6
  end
@@ -14,8 +14,11 @@ module RestfulQuery
14
14
  def self.restful_query_parser(query_hash, options = {})
15
15
  RestfulQuery::Parser.new(query_hash, @query_options.merge(options))
16
16
  end
17
-
18
- named_scope :restful_query, lambda {|query_hash|
17
+
18
+ scope_meth = self.respond_to?(:scope) ? :scope : :named_scope
19
+
20
+ send(scope_meth, :restful_query, lambda {|query_hash|
21
+ return {} if query_hash.blank? || query_hash.empty?
19
22
  parser = self.restful_query_parser(query_hash)
20
23
  query_hash = {}
21
24
  query_hash[:conditions] = parser.to_conditions_array if parser.has_conditions?
@@ -23,14 +26,14 @@ module RestfulQuery
23
26
  query_hash[:order] = parser.sort_sql if parser.has_sort?
24
27
  logger.info 'Rest query:' + query_hash.inspect
25
28
  query_hash
26
- }
29
+ })
27
30
  end
28
31
  end
29
-
32
+
30
33
  def can_query?
31
34
  @can_query
32
35
  end
33
36
  end
34
-
37
+
35
38
  end
36
- end
39
+ end
data/lib/restful_query.rb CHANGED
@@ -1,22 +1,19 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ require 'active_support'
4
5
  begin
5
6
  require 'chronic'
6
- unless defined?(ActiveSupport)
7
- require 'active_support'
8
- end
9
7
  rescue LoadError
10
8
  warn 'In order to use the time parsing functionalities you must install the Chronic gem: sudo gem install chronic'
11
9
  end
12
10
 
13
11
  module RestfulQuery
14
- VERSION = '0.3.1'
15
-
12
+ VERSION = '0.3.2'
13
+
16
14
  class Error < RuntimeError; end
17
15
  end
18
16
 
19
-
20
17
  %w{condition sort parser can_query}.each do |lib|
21
18
  require File.join("restful_query","#{lib}.rb")
22
19
  end
data/rails/init.rb CHANGED
@@ -1,3 +1,3 @@
1
- require File.join(File.dirname(__FILE__),'..','lib','restful_query.rb')
1
+ require File.join(File.expand_path(File.dirname(__FILE__)),'..','lib','restful_query.rb')
2
2
 
3
- ActiveRecord::Base.send(:include, RestfulQuery::CanQuery)
3
+ ActiveRecord::Base.send(:include, RestfulQuery::CanQuery)
@@ -1,60 +1,58 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{restful_query}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = %q{2010-02-16}
12
+ s.date = %q{2011-04-23}
13
13
  s.description = %q{RestfulQuery provides a simple interface in front of a complex parser to parse specially formatted query hashes into complex SQL queries. It includes ActiveRecord and Sequel extensions.}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
16
- "README.rdoc"
16
+ "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "History.txt",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "init.rb",
25
- "lib/restful_query.rb",
26
- "lib/restful_query/can_query.rb",
27
- "lib/restful_query/condition.rb",
28
- "lib/restful_query/parser.rb",
29
- "lib/restful_query/sort.rb",
30
- "lib/sequel/extensions/restful_query.rb",
31
- "rails/init.rb",
32
- "restful_query.gemspec",
33
- "tasks/restful_query_tasks.rake",
34
- "test/test_helper.rb",
35
- "test/test_restful_query_can_query.rb",
36
- "test/test_restful_query_condition.rb",
37
- "test/test_restful_query_parser.rb",
38
- "test/test_restful_query_sort.rb"
19
+ "History.txt",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "init.rb",
24
+ "lib/restful_query.rb",
25
+ "lib/restful_query/can_query.rb",
26
+ "lib/restful_query/condition.rb",
27
+ "lib/restful_query/parser.rb",
28
+ "lib/restful_query/sort.rb",
29
+ "lib/sequel/extensions/restful_query.rb",
30
+ "rails/init.rb",
31
+ "restful_query.gemspec",
32
+ "tasks/restful_query_tasks.rake",
33
+ "test/test_helper.rb",
34
+ "test/test_restful_query_can_query.rb",
35
+ "test/test_restful_query_condition.rb",
36
+ "test/test_restful_query_parser.rb",
37
+ "test/test_restful_query_sort.rb"
39
38
  ]
40
- s.rdoc_options = ["--charset=UTF-8"]
41
39
  s.require_paths = ["lib"]
42
40
  s.rubyforge_project = %q{quirkey}
43
- s.rubygems_version = %q{1.3.5}
41
+ s.rubygems_version = %q{1.3.7}
44
42
  s.summary = %q{Simple ActiveRecord and Sequel queries from a RESTful and safe interface}
45
43
  s.test_files = [
46
44
  "test/test_helper.rb",
47
- "test/test_restful_query_can_query.rb",
48
- "test/test_restful_query_condition.rb",
49
- "test/test_restful_query_parser.rb",
50
- "test/test_restful_query_sort.rb"
45
+ "test/test_restful_query_can_query.rb",
46
+ "test/test_restful_query_condition.rb",
47
+ "test/test_restful_query_parser.rb",
48
+ "test/test_restful_query_sort.rb"
51
49
  ]
52
50
 
53
51
  if s.respond_to? :specification_version then
54
52
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
53
  s.specification_version = 3
56
54
 
57
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
56
  s.add_runtime_dependency(%q<activesupport>, [">= 2.2.0"])
59
57
  s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
60
58
  s.add_development_dependency(%q<Shoulda>, [">= 1.2.0"])
data/test/test_helper.rb CHANGED
@@ -2,7 +2,8 @@ require 'test/unit'
2
2
  require 'rubygems'
3
3
  require 'shoulda'
4
4
 
5
- require File.join(File.dirname(__FILE__), '..', 'lib','restful_query.rb')
5
+ $LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..'))
6
+ require 'lib/restful_query'
6
7
 
7
8
 
8
9
  unless defined?(ActiveRecord)
@@ -14,12 +15,12 @@ unless defined?(ActiveRecord)
14
15
  def protected_attributes
15
16
  []
16
17
  end
17
-
18
+
18
19
  def named_scope(name, options = {})
19
20
  end
20
21
  end
21
22
  self.pluralize_table_names = true
22
-
23
+
23
24
  include RestfulQuery::CanQuery
24
25
  end
25
26
  end
@@ -30,5 +31,5 @@ class ClassWithQuery < ActiveRecord::Base
30
31
  end
31
32
 
32
33
  class ClassWithoutQuery < ActiveRecord::Base
33
-
34
- end
34
+
35
+ end
@@ -56,77 +56,77 @@ class RestfulQueryConditionTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  should "parse value with chronic" do
59
- assert_equal(1.week.ago.to_s, @condition.value.to_s)
59
+ assert_equal(Chronic.parse('1 week ago').to_s, @condition.value.to_s)
60
60
  end
61
61
  end
62
-
62
+
63
63
  context "with a value of ':nil'" do
64
64
  setup do
65
65
  @condition = RestfulQuery::Condition.new('created_at', ':nil')
66
66
  end
67
-
67
+
68
68
  should "convert value to true nil" do
69
69
  assert_equal(nil, @condition.value)
70
70
  end
71
71
  end
72
-
72
+
73
73
  context "with a value of ':true'" do
74
74
  setup do
75
75
  @condition = RestfulQuery::Condition.new('created_at', ':true')
76
76
  end
77
-
77
+
78
78
  should "convert value to true true" do
79
79
  assert_equal(true, @condition.value)
80
80
  end
81
81
  end
82
-
82
+
83
83
  context "with a value of ':blank'" do
84
84
  setup do
85
85
  @condition = RestfulQuery::Condition.new('created_at', ':blank')
86
86
  end
87
-
87
+
88
88
  should "convert value to true true" do
89
89
  assert_equal('', @condition.value)
90
90
  end
91
91
  end
92
-
92
+
93
93
  context "with the IN operator" do
94
94
  setup do
95
95
  @condition = RestfulQuery::Condition.new('year', '1995,2005,2006', 'in')
96
96
  end
97
-
97
+
98
98
  should "assign the operator" do
99
99
  assert_equal 'IN', @condition.operator
100
100
  end
101
-
101
+
102
102
  should "split values by the delimiter option" do
103
103
  assert_equal ['1995', '2005', '2006'], @condition.value
104
104
  end
105
-
105
+
106
106
  should "include parens in placeholder" do
107
107
  assert_equal ["year IN (?)", ['1995', '2005', '2006']], @condition.to_condition_array
108
108
  end
109
-
109
+
110
110
  context "when the value is already an array" do
111
111
  setup do
112
112
  @condition = RestfulQuery::Condition.new('year', ['1995', '2005', '2006'], 'in')
113
113
  end
114
-
114
+
115
115
  should "not resplit the value" do
116
116
  assert_equal ['1995', '2005', '2006'], @condition.value
117
117
  end
118
118
  end
119
119
  end
120
-
120
+
121
121
  context "with the NOT IN operator" do
122
122
  setup do
123
123
  @condition = RestfulQuery::Condition.new('year', '1995|2005|2006', 'notin', :delimiter => '|')
124
124
  end
125
-
125
+
126
126
  should "assign the operator" do
127
127
  assert_equal 'NOT IN', @condition.operator
128
128
  end
129
-
129
+
130
130
  should "split values by delimiter option" do
131
131
  assert_equal ['1995', '2005', '2006'], @condition.value
132
132
  end
@@ -138,23 +138,23 @@ class RestfulQueryConditionTest < Test::Unit::TestCase
138
138
  setup do
139
139
  @condition = RestfulQuery::Condition.new('title', 'Bossman', 'lt')
140
140
  end
141
-
141
+
142
142
  context "with operator = like to condition array" do
143
143
  setup do
144
144
  @condition = RestfulQuery::Condition.new('title', 'Bossman', 'like')
145
145
  @to_condition_array = @condition.to_condition_array
146
146
  end
147
-
147
+
148
148
  should "wrap value with %" do
149
149
  assert_equal "%Bossman%", @to_condition_array[1]
150
150
  end
151
-
151
+
152
152
  should "translate operator to LIKE" do
153
153
  assert_equal("title LIKE ?", @to_condition_array[0])
154
154
  end
155
-
155
+
156
156
  end
157
-
157
+
158
158
  context "to_condition_array" do
159
159
  setup do
160
160
  @to_condition = @condition.to_condition_array
@@ -172,7 +172,7 @@ class RestfulQueryConditionTest < Test::Unit::TestCase
172
172
  assert_equal @condition.value, @to_condition[1]
173
173
  end
174
174
  end
175
-
175
+
176
176
  context "to_hash" do
177
177
  should "return hash like params" do
178
178
  assert_equal({'title' => {'lt' => 'Bossman'}}, @condition.to_hash)
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 2
9
+ version: 0.3.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Aaron Quint
@@ -9,39 +14,54 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-16 00:00:00 -05:00
17
+ date: 2011-04-23 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 2
31
+ - 0
23
32
  version: 2.2.0
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: chronic
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 2
46
+ - 3
33
47
  version: 0.2.3
34
- version:
48
+ type: :runtime
49
+ version_requirements: *id002
35
50
  - !ruby/object:Gem::Dependency
36
51
  name: Shoulda
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
40
55
  requirements:
41
56
  - - ">="
42
57
  - !ruby/object:Gem::Version
58
+ segments:
59
+ - 1
60
+ - 2
61
+ - 0
43
62
  version: 1.2.0
44
- version:
63
+ type: :development
64
+ version_requirements: *id003
45
65
  description: RestfulQuery provides a simple interface in front of a complex parser to parse specially formatted query hashes into complex SQL queries. It includes ActiveRecord and Sequel extensions.
46
66
  email:
47
67
  executables: []
@@ -52,7 +72,6 @@ extra_rdoc_files:
52
72
  - LICENSE
53
73
  - README.rdoc
54
74
  files:
55
- - .gitignore
56
75
  - History.txt
57
76
  - LICENSE
58
77
  - README.rdoc
@@ -77,26 +96,30 @@ homepage:
77
96
  licenses: []
78
97
 
79
98
  post_install_message:
80
- rdoc_options:
81
- - --charset=UTF-8
99
+ rdoc_options: []
100
+
82
101
  require_paths:
83
102
  - lib
84
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
85
105
  requirements:
86
106
  - - ">="
87
107
  - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
88
110
  version: "0"
89
- version:
90
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
91
113
  requirements:
92
114
  - - ">="
93
115
  - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
94
118
  version: "0"
95
- version:
96
119
  requirements: []
97
120
 
98
121
  rubyforge_project: quirkey
99
- rubygems_version: 1.3.5
122
+ rubygems_version: 1.3.7
100
123
  signing_key:
101
124
  specification_version: 3
102
125
  summary: Simple ActiveRecord and Sequel queries from a RESTful and safe interface
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .DS_Store
2
- tmp*
3
- pkg*
4
- .specification
5
- _site*