sort_n_params 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/lib/sort_n_params/concerns/scopes.rb +6 -4
- data/lib/sort_n_params/sortable.rb +1 -1
- data/sort_n_params.gemspec +6 -4
- data/spec/concerns/scopes_spec.rb +25 -0
- data/spec/spec_helper.rb +1 -0
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1699472fa73140a298c054ba1cf30a75c1f08a38cfa991d2b0d738bed8b707a0
|
4
|
+
data.tar.gz: fa259494066c8118ce818a88169b771631550bd8b20dbf39c3966230abc24c54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b7d0e7c550936f4f85a2312935b138490dcce4f252240465b28eac3e4c7268fa87a089607824af3165934abdb1a8e59fdb2f5412e8684c45e6b8980fc666814
|
7
|
+
data.tar.gz: 8f406482183c6f110e9eb13a30a0fbbfe85052c5c235b4e0d3366d879632de367c561b06b984184cef0ca01f737aa81a1f2288d2506663beb477d5e061b69eee
|
data/.travis.yml
ADDED
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
@@ -4,15 +4,17 @@ module SortNParams
|
|
4
4
|
module Scopes
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
class_methods do
|
7
|
-
def sorting_order(ordering_array)
|
7
|
+
def sorting_order(ordering_array, table_name = nil)
|
8
8
|
return all if ordering_array.blank?
|
9
9
|
|
10
|
-
all.order(parse_array(ordering_array))
|
10
|
+
all.order(parse_array(ordering_array, table_name))
|
11
11
|
end
|
12
12
|
|
13
|
-
def parse_array(ordering_array)
|
13
|
+
def parse_array(ordering_array, table_name = nil)
|
14
|
+
table = table_name || name.tableize
|
15
|
+
|
14
16
|
ordering_array.each_slice(2).map do |order, direction|
|
15
|
-
"#{
|
17
|
+
"#{table}.#{order} #{direction}"
|
16
18
|
end.join(', ')
|
17
19
|
end
|
18
20
|
end
|
data/sort_n_params.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'sort_n_params'
|
3
|
-
s.version = '1.0.
|
3
|
+
s.version = '1.0.4'
|
4
4
|
s.date = '2019-05-07'
|
5
5
|
s.summary = "Sort N Params"
|
6
6
|
s.description = "Make your html <tables> sortables with N <th> parameters this gem."
|
@@ -8,14 +8,16 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = 'juannferrari@gmail.com'
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.files = [
|
11
|
+
".travis.yml",
|
11
12
|
"Gemfile",
|
12
|
-
"
|
13
|
+
"LICENSE",
|
13
14
|
"Rakefile",
|
14
15
|
"sort_n_params.gemspec",
|
15
16
|
"lib/sort_n_params.rb",
|
16
17
|
"lib/sort_n_params/sortable.rb",
|
17
18
|
"lib/sort_n_params/sort_helpers.rb",
|
18
19
|
"lib/sort_n_params/concerns/scopes.rb",
|
20
|
+
"spec/concerns/scopes_spec.rb",
|
19
21
|
"spec/spec_helper.rb",
|
20
22
|
"spec/sortable_spec.rb"
|
21
23
|
]
|
@@ -27,10 +29,10 @@ Gem::Specification.new do |s|
|
|
27
29
|
s.add_development_dependency "bundler"
|
28
30
|
s.add_development_dependency "factory_bot", "~> 4.0"
|
29
31
|
s.add_development_dependency "pry-byebug"
|
30
|
-
s.add_development_dependency "rake", "
|
32
|
+
s.add_development_dependency "rake", ">= 12.3.3"
|
31
33
|
s.add_development_dependency "rspec", "~> 3.0"
|
32
34
|
|
33
35
|
s.add_dependency(%q<rails>.freeze, ["~> 5.0"])
|
34
36
|
s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
|
35
|
-
s.add_dependency(%q<rake>.freeze, ["
|
37
|
+
s.add_dependency(%q<rake>.freeze, [">= 12.3.3"])
|
36
38
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'sort_n_params/concerns/scopes'
|
2
|
+
|
3
|
+
RSpec.describe SortNParams::Scopes do
|
4
|
+
let(:test_class) do
|
5
|
+
CustomTable = Struct.new(:custom_field) do
|
6
|
+
include SortNParams::Scopes
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when you pass only an ordering array' do
|
11
|
+
subject { test_class.parse_array(["test_field","asc"]) }
|
12
|
+
|
13
|
+
it "builds the array correctly without the table_name param passed" do
|
14
|
+
expect(subject).to eq("custom_tables.test_field asc")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when you pass both ordering array and table name' do
|
19
|
+
subject { test_class.parse_array(["test_field","asc"], "another_table_name" ) }
|
20
|
+
|
21
|
+
it "builds the array correctly with the table_name param passed" do
|
22
|
+
expect(subject).to eq("another_table_name.test_field asc")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sort_n_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Francisco Ferrari
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,30 +112,32 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 12.3.3
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 12.3.3
|
125
125
|
description: Make your html <tables> sortables with N <th> parameters this gem.
|
126
126
|
email: juannferrari@gmail.com
|
127
127
|
executables: []
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
|
+
- ".travis.yml"
|
131
132
|
- Gemfile
|
132
|
-
-
|
133
|
+
- LICENSE
|
133
134
|
- Rakefile
|
134
135
|
- lib/sort_n_params.rb
|
135
136
|
- lib/sort_n_params/concerns/scopes.rb
|
136
137
|
- lib/sort_n_params/sort_helpers.rb
|
137
138
|
- lib/sort_n_params/sortable.rb
|
138
139
|
- sort_n_params.gemspec
|
140
|
+
- spec/concerns/scopes_spec.rb
|
139
141
|
- spec/sortable_spec.rb
|
140
142
|
- spec/spec_helper.rb
|
141
143
|
homepage: https://github.com/JuannFerrari/sort_n_params
|
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
|
-
rubygems_version: 3.0.
|
162
|
+
rubygems_version: 3.0.3
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: Sort N Params
|