order_order 1.1.0 → 1.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: 385eef577f3ac59c140a2acc2cc2dc87e02e6d23
4
- data.tar.gz: 72a973ad20e5bf28f3047d72181ec6299ee20298
3
+ metadata.gz: 023a7eab91c2213d2dd45cc9af4243812b6bbbb3
4
+ data.tar.gz: 9a5efb7ad508841777b3524dff0b58ec53bee98d
5
5
  SHA512:
6
- metadata.gz: ae6708c35065f7c31cab2539b466bab454a5da9ad5eef6ef80656029f4d180d844aed1a5be1c314cbf8bc44acd89400f2a023963eaafa511c50f12724111cc98
7
- data.tar.gz: c862b50aeb63a06355e393b01752d0a51226ff4528ccd7ba8e1861d4b1796e1977b89d030ad3e3ed53bcecac24a5190de0ef5aa4e347e9f614a61ba9a23362ff
6
+ metadata.gz: 9ff10890ef74e884be12bbeb77d0dfc62c49a52ba8e3667e2dbc307b2cc4b4e541861930ae60a7b5cb91b6836e49abc5f99734c6db9d64837f100c619f6bb92c
7
+ data.tar.gz: d05497e3a5c8b37b22fa514fec8176aa6e7971e2d17613a086d747aa7e2a219c4a91aec53bbfcf8c7004736e1df1de1fca41f0c1b1116f91425a333856da3af5
@@ -0,0 +1,10 @@
1
+ Changelog
2
+ =========
3
+
4
+ ## 1.2.0
5
+
6
+ - Added `case_sensitive` option to `.alphabetical` or `.reverse_alphabetical`.
7
+
8
+ ## 1.1.0
9
+
10
+ - Added `.since`
data/README.md CHANGED
@@ -46,6 +46,25 @@ There is also a finder method called `since`:
46
46
  new_users.include?(user_1) # => true
47
47
  new_users.include?(user_2) # => true
48
48
 
49
+ `.alphabetical` and `.reverse_alphabetical` take an optional parameter 'case_sensitive'
50
+ (true by default):
51
+
52
+ person_1 = Person.create(name: "Steve")
53
+ person_2 = Person.create(name: "Bill")
54
+ person_3 = Person.create(name: "dave")
55
+
56
+ puts Post.alphabetical.pluck(:name)
57
+ # => Bill
58
+ # => Steve
59
+ # => dave
60
+ puts Post.alphabetical.pluck(:name, case_sensitive: false)
61
+ # => Bill
62
+ # => dave
63
+ # => Steve
64
+
65
+ Note that `case_sensitive` has only been tested on PostgreSQL. Feel free to add
66
+ it for one of the other SQL adapters if you need it.
67
+
49
68
 
50
69
  ## Contributing
51
70
 
@@ -5,11 +5,14 @@
5
5
  module OrderOrder
6
6
  module Extensions
7
7
 
8
+ DEFAULT_ALPHABETICAL_COLUMN = :name
9
+ DEFAULT_CHRONOLOGICAL_COLUMN = :created_at
10
+
8
11
  # Order records by date, with the newest records first.
9
12
  #
10
13
  # @param column [String] the name of the column which represents the object's
11
14
  # date. Defaults to `created_at`
12
- def chronological(column=:created_at)
15
+ def chronological(column=DEFAULT_CHRONOLOGICAL_COLUMN)
13
16
  order("#{column} ASC")
14
17
  end
15
18
 
@@ -17,23 +20,31 @@ module OrderOrder
17
20
  #
18
21
  # @param column [String] the name of the column which represents the object's
19
22
  # date. Defaults to `created_at`
20
- def reverse_chronological(column=:created_at)
23
+ def reverse_chronological(column=DEFAULT_CHRONOLOGICAL_COLUMN)
21
24
  order("#{column} DESC")
22
25
  end
23
26
 
24
27
  # Order records alphabetically.
25
28
  #
26
- # @param column [String] the name of the column which represents the object's
27
- # name. Defaults to `name`
28
- def alphabetical(column=:name)
29
+ # @param column_or_options [String] the name of the column which represents the object's
30
+ # name, or a hash of options. Defaults to `"name"`.
31
+ #
32
+ # @option case_sensitive [Boolean] order case-sensitively, e.g. "C" will go
33
+ # before "b". True by default
34
+ def alphabetical(column_or_options=DEFAULT_ALPHABETICAL_COLUMN, options={})
35
+ column = get_alphabetical_column(column_or_options, options)
29
36
  order("#{column} ASC")
30
37
  end
31
38
 
32
- # Order records reverse alphabetically.
39
+ # Order records alphabetically.
33
40
  #
34
- # @param column [String] the name of the column which represents the object's
35
- # name. Defaults to `name`
36
- def reverse_alphabetical(column=:name)
41
+ # @param column_or_options [String] the name of the column which represents the object's
42
+ # name, or a hash of options. Defaults to `"name"`.
43
+ #
44
+ # @option case_sensitive [Boolean] order case-sensitively, e.g. "C" will go
45
+ # after "b". True by default
46
+ def reverse_alphabetical(column_or_options=DEFAULT_ALPHABETICAL_COLUMN, options={})
47
+ column = get_alphabetical_column(column_or_options, options)
37
48
  order("#{column} DESC")
38
49
  end
39
50
 
@@ -49,6 +60,21 @@ module OrderOrder
49
60
  def since(time)
50
61
  where("created_at > ?", time)
51
62
  end
63
+
64
+
65
+ private
66
+
67
+ def get_alphabetical_column(column_or_options, options)
68
+ if column_or_options.is_a?(Hash)
69
+ options = column_or_options
70
+ column = DEFAULT_ALPHABETICAL_COLUMN
71
+ else
72
+ column = column_or_options
73
+ end
74
+
75
+ column = "lower(#{column})" if !options.fetch(:case_sensitive, true)
76
+ column
77
+ end
52
78
  end
53
79
  end
54
80
 
@@ -1,3 +1,3 @@
1
1
  module OrderOrder
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: order_order
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Millo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-28 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - CHANGELOG.md
63
64
  - Gemfile
64
65
  - LICENSE.txt
65
66
  - README.md