admino 0.0.8 → 0.0.9
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/admino/query/configuration.rb +12 -3
- data/lib/admino/query/dsl.rb +2 -2
- data/lib/admino/query/filter_group.rb +8 -3
- data/lib/admino/version.rb +1 -1
- data/spec/admino/query/dsl_spec.rb +1 -0
- data/spec/admino/query/filter_group_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e06d7c035647ac161360ae08222d2b06b1abca0b
|
4
|
+
data.tar.gz: f223ee1b778e59436a7a61ae13b34e59710ea612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50f41c99c286533749958ead22766d0a06458eb20d0a17e1b74101c6376ea3e631515bb5cd91a00b99e287e64c2f5f7ce9d70b523c79e250ac2e1db1bd500c65
|
7
|
+
data.tar.gz: 007a6a7a9e3dc548e6bdcbab58ff960f5eb9c74013443e4d57b5c92d09eced051bd8b4684850715031e5539f1f40b3be2be62e274ff025d43d23ecd9d03f8951
|
data/CHANGELOG.md
CHANGED
@@ -20,10 +20,19 @@ module Admino
|
|
20
20
|
class FilterGroup
|
21
21
|
attr_reader :name
|
22
22
|
attr_reader :scopes
|
23
|
+
attr_reader :options
|
24
|
+
|
25
|
+
def initialize(name, scopes, options = {})
|
26
|
+
options.symbolize_keys!
|
27
|
+
options.assert_valid_keys(:include_empty_scope)
|
23
28
|
|
24
|
-
def initialize(name, scopes)
|
25
29
|
@name = name.to_sym
|
26
30
|
@scopes = scopes.map(&:to_sym)
|
31
|
+
@options = options
|
32
|
+
end
|
33
|
+
|
34
|
+
def include_empty_scope?
|
35
|
+
@options.fetch(:include_empty_scope) { false }
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
@@ -64,8 +73,8 @@ module Admino
|
|
64
73
|
end
|
65
74
|
end
|
66
75
|
|
67
|
-
def add_filter_group(name, scopes)
|
68
|
-
FilterGroup.new(name, scopes).tap do |filter_group|
|
76
|
+
def add_filter_group(name, scopes, options = {})
|
77
|
+
FilterGroup.new(name, scopes, options).tap do |filter_group|
|
69
78
|
self.filter_groups << filter_group
|
70
79
|
end
|
71
80
|
end
|
data/lib/admino/query/dsl.rb
CHANGED
@@ -15,7 +15,7 @@ module Admino
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def augment_scope(scope)
|
18
|
-
if active_scope
|
18
|
+
if active_scope && active_scope != :empty
|
19
19
|
scope.send(active_scope)
|
20
20
|
else
|
21
21
|
scope
|
@@ -35,7 +35,8 @@ module Admino
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def value
|
38
|
-
|
38
|
+
default_value = config.include_empty_scope? ? :empty : nil
|
39
|
+
params.fetch(:query, {}).fetch(param_name, default_value)
|
39
40
|
end
|
40
41
|
|
41
42
|
def param_name
|
@@ -43,7 +44,11 @@ module Admino
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def scopes
|
46
|
-
config.scopes
|
47
|
+
@scopes ||= config.scopes.dup.tap do |scopes|
|
48
|
+
if config.include_empty_scope?
|
49
|
+
scopes.unshift :empty
|
50
|
+
end
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
54
|
def i18n_key
|
data/lib/admino/version.rb
CHANGED
@@ -14,6 +14,14 @@ module Admino
|
|
14
14
|
it 'returns nil' do
|
15
15
|
expect(filter_group.active_scope).to be_nil
|
16
16
|
end
|
17
|
+
|
18
|
+
context 'if include_empty_scope is true' do
|
19
|
+
let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
|
20
|
+
|
21
|
+
it 'returns the :empty scope' do
|
22
|
+
expect(filter_group.active_scope).to eq :empty
|
23
|
+
end
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
context 'with an invalid value' do
|
@@ -22,6 +30,14 @@ module Admino
|
|
22
30
|
it 'returns nil' do
|
23
31
|
expect(filter_group.active_scope).to be_nil
|
24
32
|
end
|
33
|
+
|
34
|
+
context 'if include_empty_scope is true' do
|
35
|
+
let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
|
36
|
+
|
37
|
+
it 'returns nil' do
|
38
|
+
expect(filter_group.active_scope).to be_nil
|
39
|
+
end
|
40
|
+
end
|
25
41
|
end
|
26
42
|
|
27
43
|
context 'with a valid value' do
|
@@ -49,6 +65,14 @@ module Admino
|
|
49
65
|
it 'returns the original scope' do
|
50
66
|
expect(result).to eq scope
|
51
67
|
end
|
68
|
+
|
69
|
+
context 'if include_empty_scope is true' do
|
70
|
+
let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
|
71
|
+
|
72
|
+
it 'returns the original scope' do
|
73
|
+
expect(result).to eq scope
|
74
|
+
end
|
75
|
+
end
|
52
76
|
end
|
53
77
|
end
|
54
78
|
|
@@ -59,6 +83,19 @@ module Admino
|
|
59
83
|
expect(filter_group.is_scope_active?('bar')).to be_true
|
60
84
|
end
|
61
85
|
end
|
86
|
+
|
87
|
+
describe '#scopes' do
|
88
|
+
subject { filter_group.scopes }
|
89
|
+
|
90
|
+
context 'if include_empty_scope is true' do
|
91
|
+
let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
|
92
|
+
it { should eq [:empty, :bar] }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'else' do
|
96
|
+
it { should eq [:bar] }
|
97
|
+
end
|
98
|
+
end
|
62
99
|
end
|
63
100
|
end
|
64
101
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -35,7 +35,7 @@ class TestQuery < Admino::Query::Base
|
|
35
35
|
search_field :foo
|
36
36
|
search_field :starting_from, coerce: :to_date
|
37
37
|
|
38
|
-
filter_by :bar, [:one, :two]
|
38
|
+
filter_by :bar, [:one, :two], include_empty_scope: true
|
39
39
|
|
40
40
|
sorting :by_title, :by_date,
|
41
41
|
default_scope: :by_title,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: admino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: showcase
|
@@ -249,4 +249,3 @@ test_files:
|
|
249
249
|
- spec/admino/table/resource_row_spec.rb
|
250
250
|
- spec/admino/table/row_spec.rb
|
251
251
|
- spec/spec_helper.rb
|
252
|
-
has_rdoc:
|