pose 3.1.1 → 3.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1059e7c72d577be6f7d5f3c0fc4fdc30b429bd4b
4
- data.tar.gz: d0ed2c994af2326ec73a779b0fb61a44dca2602b
3
+ metadata.gz: 8db9b6071e06f6087a846679cdc670014c529912
4
+ data.tar.gz: 4a26e6c1f7eb94095ce043c0988bf52f2837042a
5
5
  SHA512:
6
- metadata.gz: a9eb63377caee2f07d3e7c9118ee9715d9e386371ca766aeb35b98eabe8d76f2d2128a27188ce71dd5f05c61e8bc46dc9726a351278392fc478dcb38aeeb44f6
7
- data.tar.gz: 28e599e762c76d35070e5d81c71c9b7069270dbd3f1da463db8eb1f6f546830062da027e6eb47a794d85efa475680f66052e7c8373462bbcbdb9b9b0bbd2d37f
6
+ metadata.gz: 3d3408a071bf09401875d1dfa9361d3c7957a83e922097301522e53471bdf94de90498a723ba4458de211620732c2bcdfbb369688ba6881d46e28d2176e14007
7
+ data.tar.gz: 77f315779994035ec62b32015d9030aa8a95684526d184c1584466cc331bc8b19c8dc47762126bb571e40d901d5d421d7e9ec1096faad4b22f46a08ea285134f
data/README.md CHANGED
@@ -191,6 +191,22 @@ result = Pose.search 'foo',
191
191
  Combining ActiveRecord query clauses with fulltext search only works when searching over a single class.
192
192
 
193
193
 
194
+ ### Customize the SELECT clause with which results are loaded
195
+
196
+ This feature only makes sense if you load one result class.
197
+ It allows to only read the given set of attributes from the database.
198
+ The only use case for this is performance optimization.
199
+
200
+ ```ruby
201
+ result = Pose.search 'foo',
202
+ Note,
203
+ select: 'id, text'
204
+ ```
205
+
206
+ This query returns all Notes that have 'foo' in their text, but loads only their
207
+ `id` and `text` attributes from the database.
208
+
209
+
194
210
  ## Maintenance
195
211
 
196
212
  Besides an accasional search index cleanup, Pose is relatively maintenance free.
@@ -22,7 +22,7 @@ module Pose
22
22
  # The names of the classes to search in.
23
23
  # @return [Array<String>]
24
24
  def class_names
25
- classes.map &:name
25
+ classes.map(&:name)
26
26
  end
27
27
 
28
28
 
@@ -38,6 +38,11 @@ module Pose
38
38
  end
39
39
 
40
40
 
41
+ # Returns whether this query has a custom SELECT clause.
42
+ def has_select
43
+ @options[:select].present?
44
+ end
45
+
41
46
  # Returns whether this query contains WHERE clauses.
42
47
  def has_where?
43
48
  @options[:where].present?
@@ -10,6 +10,7 @@ module Pose
10
10
  # @param options Additional search options:
11
11
  # * where: additional where clauses
12
12
  # * join: additional join clauses
13
+ # * select: custom select clause
13
14
  def initialize classes, query_string, options = {}
14
15
  @query = Query.new classes, query_string, options
15
16
  end
@@ -68,6 +69,9 @@ module Pose
68
69
  result.each do |clazz, ids|
69
70
  if ids.size > 0
70
71
  result[clazz] = clazz.where(id: ids)
72
+ if @query.has_select
73
+ result[clazz] = result[clazz].select(@query.options[:select])
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -1,3 +1,3 @@
1
1
  module Pose
2
- VERSION = "3.1.1"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -39,31 +39,31 @@ module Pose
39
39
  describe 'is_url?' do
40
40
 
41
41
  it 'returns TRUE if the given string is a URL' do
42
- expect(Query.is_url? 'http://web.com').to be_true
42
+ expect(Query.is_url? 'http://web.com').to be_truthy
43
43
  end
44
44
 
45
45
  it 'returns TRUE if the given string is localhost' do
46
- expect(Query.is_url? 'http://localhost').to be_true
46
+ expect(Query.is_url? 'http://localhost').to be_truthy
47
47
  end
48
48
 
49
49
  it 'returns TRUE if localhost has a port' do
50
- expect(Query.is_url? 'http://localhost:3000').to be_true
50
+ expect(Query.is_url? 'http://localhost:3000').to be_truthy
51
51
  end
52
52
 
53
53
  it 'returns TRUE if the given url has a port' do
54
- expect(Query.is_url? 'http://web.com:8080').to be_true
54
+ expect(Query.is_url? 'http://web.com:8080').to be_truthy
55
55
  end
56
56
 
57
57
  it 'returns TRUE if the given string is a HTTPS URL' do
58
- expect(Query.is_url? 'https://web.com').to be_true
58
+ expect(Query.is_url? 'https://web.com').to be_truthy
59
59
  end
60
60
 
61
61
  it 'returns FALSE if the given string is not a URL' do
62
- expect(Query.is_url? 'foo').to be_false
62
+ expect(Query.is_url? 'foo').to be_falsy
63
63
  end
64
64
 
65
65
  it 'returns FALSE if the given string is a malformed URL' do
66
- expect(Query.is_url? 'http://web').to be_false
66
+ expect(Query.is_url? 'http://web').to be_falsy
67
67
  end
68
68
  end
69
69
 
@@ -120,7 +120,9 @@ module Pose
120
120
 
121
121
 
122
122
  describe :load_classes do
123
+
123
124
  context 'when the user wants ids' do
125
+
124
126
  it 'does nothing' do
125
127
  search = Search.new nil, nil, result_type: :ids
126
128
  result = { PosableOne => [1, 2] }
@@ -130,6 +132,7 @@ module Pose
130
132
  end
131
133
 
132
134
  context 'when the user wants classes' do
135
+
133
136
  it 'loads the classes' do
134
137
  object_1 = create :posable_one
135
138
  object_2 = create :posable_one
@@ -139,6 +142,23 @@ module Pose
139
142
  expect(result[PosableOne]).to eq [object_1, object_2]
140
143
  end
141
144
  end
145
+
146
+ context 'when the user specifies a select clause' do
147
+
148
+ it 'loads only the specified attributes' do
149
+ object_1 = create :posable_one
150
+ object_2 = create :posable_one
151
+ result = { PosableOne => [object_1.id, object_2.id] }
152
+ search = Search.new nil, nil, select: 'id'
153
+ search.load_classes result
154
+ expect(result[PosableOne][0].id).to eq object_1.id
155
+ expect(result[PosableOne][0].attribute_present? :text).to be_falsy
156
+ expect(result[PosableOne][0].attribute_present? :id).to be_truthy
157
+ expect(result[PosableOne][1].id).to eq object_2.id
158
+ expect(result[PosableOne][1].attribute_present? :text).to be_falsy
159
+ expect(result[PosableOne][1].attribute_present? :id).to be_truthy
160
+ end
161
+ end
142
162
  end
143
163
 
144
164
 
@@ -286,6 +286,24 @@ module Pose
286
286
 
287
287
  it 'allows to load data from joined tables'
288
288
  end
289
+
290
+
291
+ describe ':select parameter' do
292
+
293
+ before :each do
294
+ @one = create :posable_one, text: 'snippet one', user: @user_1
295
+ @two = create :posable_one, text: 'snippet two', user: @user_2
296
+ end
297
+
298
+ it 'makes Pose load only the given fields' do
299
+ result = Pose.search 'snippet',
300
+ PosableOne,
301
+ { select: 'id' }
302
+ first_result = result[PosableOne].first
303
+ expect(first_result.id).to eq @one.id
304
+ expect(first_result.attribute_present? :text).to be_falsy
305
+ end
306
+ end
289
307
  end
290
308
 
291
309
 
@@ -325,19 +343,19 @@ module Pose
325
343
 
326
344
  it 'recognizes mysql databases' do
327
345
  ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::Mysql2Adapter'
328
- expect(Pose.has_sql_connection?).to be_true
346
+ expect(Pose.has_sql_connection?).to be_truthy
329
347
  ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
330
- expect(Pose.has_sql_connection?).to be_true
348
+ expect(Pose.has_sql_connection?).to be_truthy
331
349
  end
332
350
 
333
351
  it 'recognizes postgres databases' do
334
352
  ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
335
- expect(Pose.has_sql_connection?).to be_true
353
+ expect(Pose.has_sql_connection?).to be_truthy
336
354
  end
337
355
 
338
356
  it 'recognizes sqlite3 databases' do
339
357
  ActiveRecord::Base.connection.class.stub(:name).and_return 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
340
- expect(Pose.has_sql_connection?).to be_true
358
+ expect(Pose.has_sql_connection?).to be_truthy
341
359
  end
342
360
  end
343
361
  end
@@ -6,6 +6,8 @@ end
6
6
  require 'factory_girl'
7
7
  require 'faker'
8
8
  require 'pose'
9
+ require 'rspec/its'
10
+ require 'rspec/collection_matchers'
9
11
 
10
12
  Dir["#{File.dirname __FILE__}/factories/**/*.rb"].each {|f| require f}
11
13
  Dir["#{File.dirname __FILE__}/support/**/*.rb"].each {|f| require f}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pose
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Goslar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-collection_matchers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: sqlite3
99
127
  requirement: !ruby/object:Gem::Requirement