mongo-search 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongo-search (0.0.1)
4
+ mongo-search (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -2,6 +2,7 @@ module MongoSearch
2
2
  class Sorter
3
3
  def initialize(attr, opts = nil)
4
4
  @attr, @opts = attr, opts || {}
5
+ @mappings = @opts[:mappings] || {}
5
6
  end
6
7
 
7
8
  def call(params)
@@ -10,9 +11,9 @@ module MongoSearch
10
11
  if order_by = params[@attr] || @opts[:default]
11
12
  order_by.split(/\s*,\s*/).each do |attr_order|
12
13
  if attr_order =~ /([^\s]+)(?:\s*(asc|desc)?)$/
13
- attr_name, dir = $1, ($2 || :asc)
14
- sort << [:"#{attr_name}_ordenacao", :"#{dir}"]
15
- sort << [:"#{attr_name}", :"#{dir}"]
14
+ attr_name, dir = $1.to_sym, ($2 || :asc).to_sym
15
+ attr_name = @mappings[attr_name] if @mappings[attr_name]
16
+ sort << [attr_name, dir]
16
17
  else
17
18
  raise ArgumentError, "invalid sorting parameters: #{order_by}"
18
19
  end
@@ -1,5 +1,5 @@
1
1
  module Mongo
2
2
  module Search
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@ describe "Search integration" do
16
16
  c.intersect :tags
17
17
  c.less_than :updated_before, :field => :updated_at, :type => :time, :equal => true
18
18
  c.greater_than :updated_since, :field => :updated_at, :type => :time, :equal => true
19
- c.sort_with :order, :default => "name asc"
19
+ c.sort_with :order, :default => "name asc", :mappings => {:titulo => :titulo_ordenacao}
20
20
  end
21
21
  end
22
22
 
@@ -52,19 +52,18 @@ describe "Search integration" do
52
52
  c.should == {:updated_at => {:$lte => time}}
53
53
  end
54
54
 
55
- it "uses specified sorting and includes a _ordenacao prefix also" do
55
+ it "uses specified sorting respecting custom mappings" do
56
56
  _, s = subject.criteria_for :order => "titulo desc"
57
- s.should == [[:titulo_ordenacao, :desc], [:titulo, :desc]]
57
+ s.should == [[:titulo_ordenacao, :desc]]
58
58
  end
59
59
 
60
- it "defaults sorting direction to asc if not specified" do
60
+ it "combine sortings properly" do
61
61
  _, s = subject.criteria_for :order => "titulo, categoria"
62
- s.should include([:titulo, :asc])
63
- s.should include([:categoria, :asc])
62
+ s.should == [[:titulo_ordenacao, :asc], [:categoria, :asc]]
64
63
  end
65
64
 
66
65
  it "uses default sorting if no specified" do
67
66
  _, s = subject.criteria_for({})
68
- s.should == [[:name_ordenacao, :asc], [:name, :asc]]
67
+ s.should == [[:name, :asc]]
69
68
  end
70
69
  end
metadata CHANGED
@@ -1,57 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongo-search
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Rodrigo Kochenburger <divoxx@gmail.com>
9
14
  - Tomas Mattia <tomas.mattia@gmail.com>
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2012-05-22 00:00:00.000000000Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rspec
17
- requirement: &70349984450400 !ruby/object:Gem::Requirement
18
+
19
+ date: 2012-07-04 00:00:00 -03:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ requirement: &id001 !ruby/object:Gem::Requirement
18
24
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :development
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ version_requirements: *id001
33
+ name: rspec
24
34
  prerelease: false
25
- version_requirements: *70349984450400
26
- - !ruby/object:Gem::Dependency
27
- name: guard
28
- requirement: &70349984449940 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
35
  type: :development
35
- prerelease: false
36
- version_requirements: *70349984449940
37
- - !ruby/object:Gem::Dependency
38
- name: guard-rspec
39
- requirement: &70349984449320 !ruby/object:Gem::Requirement
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ version_requirements: *id002
47
+ name: guard
48
+ prerelease: false
45
49
  type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ version_requirements: *id003
61
+ name: guard-rspec
46
62
  prerelease: false
47
- version_requirements: *70349984449320
63
+ type: :development
48
64
  description:
49
- email:
65
+ email:
50
66
  - abril_vejasp_dev@thoughtworks.com
51
67
  executables: []
68
+
52
69
  extensions: []
70
+
53
71
  extra_rdoc_files: []
54
- files:
72
+
73
+ files:
55
74
  - .gitignore
56
75
  - Gemfile
57
76
  - Gemfile.lock
@@ -71,31 +90,40 @@ files:
71
90
  - mongo-search.gemspec
72
91
  - spec/search_spec.rb
73
92
  - spec/spec_helper.rb
74
- homepage: ''
93
+ has_rdoc: true
94
+ homepage: ""
75
95
  licenses: []
96
+
76
97
  post_install_message:
77
98
  rdoc_options: []
78
- require_paths:
99
+
100
+ require_paths:
79
101
  - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
102
+ required_ruby_version: !ruby/object:Gem::Requirement
81
103
  none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
112
  none: false
88
- requirements:
89
- - - ! '>='
90
- - !ruby/object:Gem::Version
91
- version: '0'
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
92
120
  requirements: []
121
+
93
122
  rubyforge_project: mongo-search
94
- rubygems_version: 1.8.10
123
+ rubygems_version: 1.6.2
95
124
  signing_key:
96
125
  specification_version: 3
97
126
  summary: Easy search for mongodb
98
- test_files:
127
+ test_files:
99
128
  - spec/search_spec.rb
100
129
  - spec/spec_helper.rb
101
- has_rdoc: