order_order 0.0.1 → 1.0.0

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
  SHA1:
3
- metadata.gz: aceca7dca7240c7849844975ea6dc4cf50cb00b5
4
- data.tar.gz: 800f62cb1ef69368d11e28b7cb5cc4ddbb90ac6d
3
+ metadata.gz: a26645f321275ccfdaa5139bf30ff8a9665988f9
4
+ data.tar.gz: 5007c39623d4b65dbfe2c56d2be9abc81859cb91
5
5
  SHA512:
6
- metadata.gz: db0b8e6974dadb0cc17d3162ee2f5110c2c377220e88b6c2b7d1ffa32bd31c640488502bb28f44cb9a3db86f27064c577508c16c54319266303b3ee01cd58a7d
7
- data.tar.gz: a52c1dcc964cc6d8e7fc213a35adee59c37635ccb020572a6a56ccdb09d384d8bfb0050dbae38d4e4232fd5e48854954e3827da22e67d54bbb4ccdd5c79edd7e
6
+ metadata.gz: 2077144f2407104227e9d3bfd4588607689f00a8c34cf9f2472c12f16c1ec5e48b1b632f584ed26477362c43d72c6e691712df4658b4d3a866d54de4cd410607
7
+ data.tar.gz: cd46ef598a7371cd7904456fafc3111d076642264d9e239d74c2177aa0c6fd9b3393f077ac1fc6183923d49c759c281d761b4fdc033442ce349713039d8ea1d6
@@ -0,0 +1,47 @@
1
+ # Extension for ActiveRecord::Base which adds some common sorting options.
2
+ #
3
+ # WARNING: **Never** allow allow user-generated input to be passed in as the
4
+ # values of these methods! It would leave you wide open to SQL injection.
5
+ module OrderOrder
6
+ module Extensions
7
+
8
+ # Order records by date, with the newest records first.
9
+ #
10
+ # @param column [String] the name of the column which represents the object's
11
+ # date. Defaults to `created_at`
12
+ def chronological(column=:created_at)
13
+ order("#{column} ASC")
14
+ end
15
+
16
+ # Order records by date, with the oldest records first.
17
+ #
18
+ # @param column [String] the name of the column which represents the object's
19
+ # date. Defaults to `created_at`
20
+ def reverse_chronological(column=:created_at)
21
+ order("#{column} DESC")
22
+ end
23
+
24
+ # Order records alphabetically.
25
+ #
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
+ order("#{column} ASC")
30
+ end
31
+
32
+ # Order records reverse alphabetically.
33
+ #
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)
37
+ order("#{column} DESC")
38
+ end
39
+
40
+ # TODO A potential way to improve this: setting `self.chronological_column`
41
+ # or `self.name_column` at the model level would negate the need to pass an
42
+ # argument to these methods.
43
+
44
+ end
45
+ end
46
+
47
+ ActiveRecord::Base.send(:extend, OrderOrder::Extensions)
@@ -1,3 +1,3 @@
1
1
  module OrderOrder
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/order_order.rb CHANGED
@@ -1,5 +1,2 @@
1
1
  require "order_order/version"
2
-
3
- module OrderOrder
4
- # Your code goes here...
5
- end
2
+ require "order_order/extensions"
data/order_order.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "activerecord"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.7"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: order_order
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Millo
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +65,7 @@ files:
51
65
  - README.md
52
66
  - Rakefile
53
67
  - lib/order_order.rb
68
+ - lib/order_order/extensions.rb
54
69
  - lib/order_order/version.rb
55
70
  - order_order.gemspec
56
71
  homepage: http://github.com/headstock/order_order