order_order 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +19 -0
- data/lib/order_order/extensions.rb +35 -9
- data/lib/order_order/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 023a7eab91c2213d2dd45cc9af4243812b6bbbb3
|
4
|
+
data.tar.gz: 9a5efb7ad508841777b3524dff0b58ec53bee98d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff10890ef74e884be12bbeb77d0dfc62c49a52ba8e3667e2dbc307b2cc4b4e541861930ae60a7b5cb91b6836e49abc5f99734c6db9d64837f100c619f6bb92c
|
7
|
+
data.tar.gz: d05497e3a5c8b37b22fa514fec8176aa6e7971e2d17613a086d747aa7e2a219c4a91aec53bbfcf8c7004736e1df1de1fca41f0c1b1116f91425a333856da3af5
|
data/CHANGELOG.md
ADDED
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
|
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
|
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
|
27
|
-
# name. Defaults to `name
|
28
|
-
|
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
|
39
|
+
# Order records alphabetically.
|
33
40
|
#
|
34
|
-
# @param
|
35
|
-
# name. Defaults to `name
|
36
|
-
|
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
|
|
data/lib/order_order/version.rb
CHANGED
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.
|
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-
|
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
|