trailblazer-finder 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4608d8c90233e27fe50241948f60646d3b68babc3555357291586f83bad3f6e
4
- data.tar.gz: 04fd61382d1ba953bbb36f115a7dad6491df8c8b86622593d859b000a16cdf69
3
+ metadata.gz: 2dbad15894d9e56c23ebe4428acfd379f5854f8948e67073ebde8c898814c1cc
4
+ data.tar.gz: f265dd84d1b25458fa630823c7c526628017d79e786e5bb362a043f75d864295
5
5
  SHA512:
6
- metadata.gz: 7723c58c1ecccad895806fde42004a1b74d478ed87020f0ea022f1e146854909c246cb7bd6e64e0bbc3c7f585a29c4bcb3d351b309bcaaa5f4fa52d581c4f219
7
- data.tar.gz: 129524c2f2ab3ac5249cdacd941405239a0f1389534b7418005e1b31bb8cba712e49df7454257047fa8a0361d1e4e0098dc2e1dafcd2925ffb77363e0a365c1e
6
+ metadata.gz: 2ae3bf32a2ece475570a67222bd371e5092df9a56bf6a195da185d6071e6877da9dc946ad3b00eed0cdefe357aab85a56b2f50eba3c0e63acc06df8f9c346354
7
+ data.tar.gz: 3aca9b67986a6c62a8c7173bc0bf34b9238b55046dc537865405f70e75e3de6b98bb72c98e39839fd8338085ce978013380f9ff4903590010cb1ba8b514f6f9d
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-03-14 21:09:38 +0100 using RuboCop version 0.53.0.
3
+ # on 2018-03-17 03:54:36 +0100 using RuboCop version 0.53.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -18,6 +18,15 @@ Layout/EmptyLines:
18
18
  Exclude:
19
19
  - 'spec/trailblazer/operation/finder_spec.rb'
20
20
 
21
+ # Offense count: 2
22
+ # Cop supports --auto-correct.
23
+ # Configuration parameters: EnforcedStyle.
24
+ # SupportedStyles: empty_lines, no_empty_lines
25
+ Layout/EmptyLinesAroundBlockBody:
26
+ Exclude:
27
+ - 'spec/trailblazer/finder/adapters/active_record/sorting_spec.rb'
28
+ - 'spec/trailblazer/finder/features/sorting_spec.rb'
29
+
21
30
  # Offense count: 1
22
31
  # Cop supports --auto-correct.
23
32
  # Configuration parameters: EnforcedStyle.
@@ -78,13 +87,12 @@ Layout/SpaceInsideParens:
78
87
  Exclude:
79
88
  - 'lib/trailblazer/finder/utils/splitter.rb'
80
89
 
81
- # Offense count: 5
90
+ # Offense count: 4
82
91
  # Cop supports --auto-correct.
83
92
  Layout/TrailingWhitespace:
84
93
  Exclude:
85
94
  - 'lib/trailblazer/finder/filter.rb'
86
95
  - 'spec/trailblazer/finder/adapters/active_record/base_spec.rb'
87
- - 'spec/trailblazer/finder/adapters/data_mapper/base_spec.rb'
88
96
  - 'spec/trailblazer/finder/adapters/sequel/base_spec.rb'
89
97
 
90
98
  # Offense count: 1
@@ -99,19 +107,21 @@ Lint/UnusedMethodArgument:
99
107
  Exclude:
100
108
  - 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
101
109
 
102
- # Offense count: 2
110
+ # Offense count: 3
103
111
  Metrics/AbcSize:
104
- Max: 18
112
+ Max: 17
105
113
 
106
- # Offense count: 8
114
+ # Offense count: 9
107
115
  # Configuration parameters: CountComments.
108
116
  Metrics/MethodLength:
109
117
  Max: 51
110
118
 
111
- # Offense count: 5
119
+ # Offense count: 7
112
120
  RSpec/DescribeClass:
113
121
  Exclude:
122
+ - 'spec/trailblazer/finder/adapters/active_record/sorting_spec.rb'
114
123
  - 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
124
+ - 'spec/trailblazer/finder/adapters/sequel/sorting_spec.rb'
115
125
  - 'spec/trailblazer/operation/finder_spec.rb'
116
126
  - 'spec/trailblazer/operation/paging_spec.rb'
117
127
  - 'spec/trailblazer/operation/predicates_spec.rb'
@@ -170,20 +180,20 @@ Style/PerlBackrefs:
170
180
  Exclude:
171
181
  - 'lib/trailblazer/finder/utils/splitter.rb'
172
182
 
173
- # Offense count: 160
183
+ # Offense count: 153
174
184
  # Cop supports --auto-correct.
175
185
  # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
176
186
  # SupportedStyles: single_quotes, double_quotes
177
187
  Style/StringLiterals:
178
188
  Exclude:
179
189
  - 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
180
- - 'lib/trailblazer/finder/features/predicate.rb'
181
190
  - 'spec/trailblazer/finder/adapters/active_record/predicates_spec.rb'
191
+ - 'spec/trailblazer/finder/adapters/active_record/sorting_spec.rb'
182
192
  - 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
183
193
  - 'spec/trailblazer/finder/features/predicates_spec.rb'
184
194
  - 'spec/trailblazer/operation/predicates_spec.rb'
185
195
 
186
- # Offense count: 16
196
+ # Offense count: 20
187
197
  # Cop supports --auto-correct.
188
198
  # Configuration parameters: EnforcedStyle, MinSize, WordRegex.
189
199
  # SupportedStyles: percent, brackets
@@ -192,9 +202,10 @@ Style/WordArray:
192
202
  - 'spec/trailblazer/finder/adapters/active_record/predicates_spec.rb'
193
203
  - 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
194
204
  - 'spec/trailblazer/finder/features/predicates_spec.rb'
205
+ - 'spec/trailblazer/finder/features/sorting_spec.rb'
195
206
  - 'spec/trailblazer/operation/predicates_spec.rb'
196
207
 
197
- # Offense count: 151
208
+ # Offense count: 174
198
209
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
199
210
  # URISchemes: http, https
200
211
  Metrics/LineLength:
@@ -3,8 +3,6 @@ before_install:
3
3
  - gem install bundler
4
4
  matrix:
5
5
  include:
6
- - rvm: 2.1
7
- gemfile: Gemfile
8
6
  - rvm: 2.2
9
7
  gemfile: Gemfile
10
8
  - rvm: 2.3.1
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.3
2
+ * Added sorting by multiple columns/directions for Hash, ActiveRecord and Sequel. Temporarily disabled sorting for DataMapper Adapter until i can find the time this weekend to update that Adapter as well.
3
+ * Due to the above, a big change in the way sorting works, and which methods are available for it
4
+
1
5
  # 0.1.2
2
6
 
3
7
  * Predicate feature introduced, doesn't work for old datamapper adapter yet. Default predicates covered for now: eq, not_eq, blank, not_blank, lt, lte, gt, gte
data/README.md CHANGED
@@ -10,37 +10,37 @@ Description should come here
10
10
  * [Installation](#installation)
11
11
  * [Dependencies](#dependencies)
12
12
  * [Usage](#usage)
13
- * [Finder](#finder)
14
- * [Finder Example](#finder-example)
15
- * [Operation](#operation)
16
- * [Operation Example](#operation-example)
17
- * [Usable without Trailblazer](#usable-without-trailblazer)
18
- * [Example without Trailblazer](#example-without-trailblazer)
19
- * [Example Project](#example-project)
20
- * [Features](#features)
13
+ * [Finder](#finder)
14
+ * [Finder Example](#finder-example)
15
+ * [Operation](#operation)
16
+ * [Operation Example](#operation-example)
17
+ * [Usable without Trailblazer](#usable-without-trailblazer)
18
+ * [Example without Trailblazer](#example-without-trailblazer)
19
+ * [Example Project](#example-project)
20
+ * [Features](#features)
21
21
  * [Predicate](#predicate)
22
22
  * [Predicate Example](#predicate-example)
23
23
  * [Paging](#paging)
24
- * [Paging Example](#paging-example)
24
+ * [Paging Example](#paging-example)
25
25
  * [Sorting](#sorting)
26
- * [Sorting Example](#sorting-example)
27
- * [Adapters](#adapters)
26
+ * [Sorting Example](#sorting-example)
27
+ * [Adapters](#adapters)
28
28
  * [Adapters Example](#adapters-example)
29
29
  * [ActiveRecord](#active_record)
30
- * [Active Record Example](#active-record-example)
30
+ * [Active Record Example](#active-record-example)
31
31
  * [DataMapper](#data_mapper)
32
- * [Data Mapper Example](#data-mapper-example)
32
+ * [Data Mapper Example](#data-mapper-example)
33
33
  * [Sequel](#sequel)
34
- * [Sequel Example](#sequel-example)
34
+ * [Sequel Example](#sequel-example)
35
35
  * [Kaminari](#kaminari)
36
- * [Kaminari Example](#kaminari-example)
36
+ * [Kaminari Example](#kaminari-example)
37
37
  * [WillPaginate](#will_paginate)
38
- * [Will Paginate Example](#will-paginate-example)
38
+ * [Will Paginate Example](#will-paginate-example)
39
39
  * [FriendlyId](#friendly_id)
40
- * [Friendly Id Example](#friendly-id-example)
40
+ * [Friendly Id Example](#friendly-id-example)
41
41
  * [Tips & Tricks](#tips--tricks)
42
42
  * [ORM's are not required](#results-shortcut)
43
- * [Passing Entity Type as Argument](#passing-entity_type-as-argument)
43
+ * [Passing Entity Type as Argument](#passing-entity_type-as-argument)
44
44
  * [Contributing](#contributing)
45
45
  * [License](#license)
46
46
 
@@ -60,7 +60,7 @@ Or install it yourself as:
60
60
 
61
61
  $ gem install trailblazer-finder
62
62
 
63
- ###
63
+ ### Dependencies
64
64
  * [Trailblazer](https://github.com/trailblazer/trailblazer) - [actually optional, but requires 2.1+](https://github.com/trailblazer/trailblazer-finder#usable-without-trailblazer)
65
65
 
66
66
  ## Usage
@@ -237,6 +237,11 @@ Coming soon!
237
237
  ## Features
238
238
  Aside of the default filtering behavior, it offers the following optional features as well.
239
239
 
240
+ Just for the record, you can comma seperate features and load multiple by doing
241
+ ```ruby
242
+ features Sorting, Paging, Predicate
243
+ ```
244
+
240
245
  NOTE: FEATURES NEED TO BE SPECIFIED ON TOP OF YOUR CLASS
241
246
 
242
247
  ### Predicate
@@ -257,13 +262,13 @@ NOTE: PREDICATES CURRENTLY DO NOT WORK FOR THE OLD DATAMAPPER ADAPTER
257
262
  #### Predicate Example
258
263
  ```ruby
259
264
  class Post::Finder < Trailblazer::Finder
260
- features Predicate
265
+ features Predicate
261
266
 
262
- # Specify the fields you want predicates enabled for, mind you these fields need to exist on your entity_type
263
- predicates_for :name, :category_name
267
+ # Specify the fields you want predicates enabled for, mind you these fields need to exist on your entity_type
268
+ predicates_for :name, :category_name
264
269
 
265
270
  filter_by :name
266
- filter_by :published
271
+ filter_by :published
267
272
  filter_by :category_name
268
273
 
269
274
  # per page defaults to 25 (so not required)
@@ -280,36 +285,36 @@ end
280
285
  This feature extends the result[:finder] object with the following methods
281
286
  ```ruby
282
287
  # accessing filters
283
- .name # => name filter
284
- .created_at # => created at filter
288
+ .name # => name filter
289
+ .created_at # => created at filter
285
290
 
286
291
  # Predicate filters
287
- .name_eq # => name equals filter
288
- .name_not_eq # => name not equals filter
289
- .name_blank # => name blank filter
290
- .name_not_blank # => name not blank filter
291
- .name_lt # => name less than filter (converts value to float)
292
- .name_lte # => name less than or equal to filter (converts value to float)
293
- .name_gt # => name greater than filter (converts value to float)
294
- .name_gte # => name greater than or equal to filter (converts value to float)
295
- .category_name_eq # => category name equals filter
296
- .category_name_not_eq # => category name not equals filter
297
- .category_name_blank # => category name blank filter
298
- .category_name_not_blank # => category name not blank filter
299
- .category_name_lt # => category name less than filter (converts value to float)
300
- .category_name_lte # => category name less than or equal to filter (converts value to float)
301
- .category_name_gt # => category name greater than filter (converts value to float)
302
- .category_name_gte # => category name greater than or equal to filter (converts value to float)
292
+ .name_eq # => name equals filter
293
+ .name_not_eq # => name not equals filter
294
+ .name_blank # => name blank filter
295
+ .name_not_blank # => name not blank filter
296
+ .name_lt # => name less than filter (converts value to float)
297
+ .name_lte # => name less than or equal to filter (converts value to float)
298
+ .name_gt # => name greater than filter (converts value to float)
299
+ .name_gte # => name greater than or equal to filter (converts value to float)
300
+ .category_name_eq # => category name equals filter
301
+ .category_name_not_eq # => category name not equals filter
302
+ .category_name_blank # => category name blank filter
303
+ .category_name_not_blank # => category name not blank filter
304
+ .category_name_lt # => category name less than filter (converts value to float)
305
+ .category_name_lte # => category name less than or equal to filter (converts value to float)
306
+ .category_name_gt # => category name greater than filter (converts value to float)
307
+ .category_name_gte # => category name greater than or equal to filter (converts value to float)
303
308
 
304
309
  # accessing results
305
- .count # => number of found results
306
- .results? # => are there any results found
307
- .results # => fetched results
308
- .all # => if needed, use it to get dataset (sequel for example requires you use it in some cases)
310
+ .count # => number of found results
311
+ .results? # => are there any results found
312
+ .results # => fetched results
313
+ .all # => if needed, use it to get dataset (sequel for example requires you use it in some cases)
309
314
 
310
315
  # params for url generations
311
- .params # => filter values
312
- .params published: false # => overwrites the 'published' filter
316
+ .params # => filter values
317
+ .params published: false # => overwrites the 'published' filter
313
318
  ```
314
319
 
315
320
  ### Paging
@@ -318,7 +323,7 @@ Really simple pagination feature, which uses the plain ```.limit``` and ```.offs
318
323
  #### Paging Example
319
324
  ```ruby
320
325
  class Post::Finder < Trailblazer::Finder
321
- features Paging
326
+ features Paging
322
327
 
323
328
  filter_by :name
324
329
  filter_by :category_name
@@ -342,12 +347,14 @@ This feature extends the result[:finder] object with the following methods
342
347
  ```
343
348
 
344
349
  ### Sorting
345
- Really simple sorting feature, fixing the pain of dealing with sorting attributes and directions. For the moment only sorting by a single attribute works, we're working on making it possible to sort by multiple attributes.
350
+ Really simple sorting feature, fixing the pain of dealing with sorting attributes and directions. Can sort by multiple columns/directions.
351
+
352
+ NOTE: AS OF 0.1.3 TEMPORARY NOT WORKING FOR DATAMAPPER ADAPTER, WE ARE WORKING ON FIXING IT
346
353
 
347
354
  #### Sorting Example
348
355
  ```ruby
349
356
  class Post::Finder < Trailblazer::Finder
350
- features Sorting
357
+ features Sorting
351
358
 
352
359
  sortable_by :name, :body
353
360
  end
@@ -356,21 +363,26 @@ end
356
363
  This feature extends the result[:finder] object with the following methods
357
364
  ```ruby
358
365
  .results # => Posts sorted by title DESC
359
- .sort_attribute # => 'title'
360
- .sort_direction # => 'desc'
361
366
 
362
367
  # Smart sort checking
363
368
  .sort?('title') # => true
364
- .sort?('title desc') # => true
365
- .sort?('title asc') # => false
366
369
 
367
- # Helpers for dealing with reversing sort direction
368
- .reverted_sort_direction # => 'asc'
370
+ # Helpers for seeing current sort direction
369
371
  .sort_direction_for('title') # => 'asc'
370
- .sort_direction_for('body') # => 'desc'
372
+ .sort_direction_for('body') # => 'desc'
371
373
 
372
- # Params for sorting links
374
+ # Helpers for seeing reversing sort direction
375
+ .reverse_sort_direction_for('title') # => 'desc'
376
+ .reverse_sort_direction_for('body') # => 'asc'
377
+
378
+ # Params for sorting links (new if none exists, existing params if exists)
373
379
  .sort_params_for('title')
380
+
381
+ # Add Params for sorting links (add to existing / replace with different direction)
382
+ .add_sort_params_for('title')
383
+
384
+ # New Params for sorting links (reset)
385
+ .new_sort_params_for('title')
374
386
  ```
375
387
 
376
388
  ## Adapters
@@ -10,8 +10,12 @@ module Trailblazer
10
10
 
11
11
  private
12
12
 
13
- def sort_it(entity_type, sort_attribute, sort_direction)
14
- entity_type.order sort_attribute.to_s => sort_direction
13
+ def sort_it(entity_type, sort_attributes)
14
+ entity_type.order(sort_attributes)
15
+ end
16
+
17
+ def sort_orders(sort_attr, sort_dir)
18
+ { sort_attr.to_s => sort_dir }
15
19
  end
16
20
  end
17
21
  end
@@ -1,5 +1,5 @@
1
1
  require 'trailblazer/finder/adapters/data_mapper/paging'
2
- require 'trailblazer/finder/adapters/data_mapper/sorting'
2
+ # require 'trailblazer/finder/adapters/data_mapper/sorting'
3
3
 
4
4
  module Trailblazer
5
5
  class Finder
@@ -23,7 +23,7 @@ module Trailblazer
23
23
  end
24
24
 
25
25
  include Paging if defined?(Features::Paging::ClassMethods)
26
- include Sorting if defined?(Features::Sorting::ClassMethods)
26
+ # include Sorting if defined?(Features::Sorting::ClassMethods)
27
27
  end
28
28
  end
29
29
  end
@@ -1,25 +1,25 @@
1
- module Trailblazer
2
- class Finder
3
- module Adapters
4
- module DataMapper
5
- # Sequel - Sorting Adapter
6
- module Sorting
7
- def self.included(base)
8
- base.extend Features::Sorting::ClassMethods
9
- end
10
-
11
- private
12
-
13
- def sort_it(entity_type, sort_attribute, sort_direction)
14
- case sort_direction
15
- when 'asc', 'ascending'
16
- entity_type.all(order: [sort_attribute.to_sym.asc])
17
- when 'desc', 'descending'
18
- entity_type.all(order: [sort_attribute.to_sym.desc])
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
1
+ # module Trailblazer
2
+ # class Finder
3
+ # module Adapters
4
+ # module DataMapper
5
+ # # Sequel - Sorting Adapter
6
+ # module Sorting
7
+ # def self.included(base)
8
+ # base.extend Features::Sorting::ClassMethods
9
+ # end
10
+ #
11
+ # private
12
+ #
13
+ # def sort_it(entity_type, sort_attribute, sort_direction)
14
+ # case sort_direction
15
+ # when 'asc', 'ascending'
16
+ # entity_type.all(order: [sort_attribute.to_sym.asc])
17
+ # when 'desc', 'descending'
18
+ # entity_type.all(order: [sort_attribute.to_sym.desc])
19
+ # end
20
+ # end
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+ # end
@@ -10,13 +10,15 @@ module Trailblazer
10
10
 
11
11
  private
12
12
 
13
- def sort_it(entity_type, sort_attribute, sort_direction)
14
- case sort_direction
15
- when 'asc', 'ascending'
16
- entity_type.order(sort_attribute.to_sym)
17
- when 'desc', 'descending'
18
- entity_type.reverse(sort_attribute.to_sym)
19
- end
13
+ def sort_orders(sort_attr, sort_dir)
14
+ ::Sequel.send sort_dir, sort_attr.to_sym
15
+ end
16
+
17
+ def sort_it(entity_type, sort_attributes)
18
+ result = []
19
+ result << [:order, sort_attributes.first] if sort_attributes.is_a? Array
20
+ sort_attributes.drop(1).each { |x| result << [:order_append, x] }
21
+ result.inject(entity_type) { |obj, method_and_args| obj.send(*method_and_args) }
20
22
  end
21
23
  end
22
24
  end