the_grid 1.1.5 → 1.1.6
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,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzE3MTZmMzNjMjc3MjI2MDg5YTM5ODQzOWQwMzNmYmRlOGM2ODRhNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
ZjgwNzUxMjdhZGEzYzFkYmZmNjQ0YjdjMjMyZjcxYTNhYjUzZjJjNQ==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjEyNDEwYTIwZDI4YjRlNGJkOTk4OWM2YmYxYWUyN2Q0NTQ2ZjJmMTY1Yzc4
|
10
|
+
MTVhMmZkNTIzZGQ2MDUyZTlkNmNhZjg1ZjA4ODc5Y2ExN2JkNGYzZWVjOTQ4
|
11
|
+
ZDA2M2VmZGZjZTZmYzRmNTdjY2I2NmU3MDgwNzAzZDM3ODc2ODk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTRhNDI4MDRiOGQ0ZjllOTYzY2U0ZWY0MTE0NTBhNWUyN2Q3OTZlMzhlZDJl
|
14
|
+
NTk2MjY3NjI0NjJhMGM3NWU3MWRhZTEwYzcxNDZjZWNjZjZkNjc5ZjVkMjA4
|
15
|
+
NTQ2NmJhMWMyOWIyYjA1ZDE0YzM2YTJkYzQ3MzRjNWI5Y2YwZGM=
|
@@ -14,15 +14,17 @@ module TheGrid
|
|
14
14
|
|
15
15
|
def build_conditions_for(relation, filters)
|
16
16
|
conditions = filters.map do |name, filter|
|
17
|
+
column = column_for(relation, name)
|
18
|
+
|
17
19
|
if filter.kind_of?(Array)
|
18
|
-
|
20
|
+
column.in(filter)
|
19
21
|
elsif filter.kind_of?(Hash)
|
20
22
|
expr = []
|
21
|
-
expr <<
|
22
|
-
expr <<
|
23
|
+
expr << column.gteq(prepare_value filter, :from) if filter.has_key?(:from)
|
24
|
+
expr << column.lteq(prepare_value filter, :to) if filter.has_key?(:to)
|
23
25
|
expr.inject(:and)
|
24
26
|
else
|
25
|
-
|
27
|
+
column.eq(filter)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
conditions.compact.inject(:and)
|
data/lib/the_grid/api/command.rb
CHANGED
@@ -52,5 +52,17 @@ module TheGrid
|
|
52
52
|
params
|
53
53
|
end
|
54
54
|
|
55
|
+
def column_for(relation, field_name)
|
56
|
+
table, field = field_name.to_s.split('.')
|
57
|
+
|
58
|
+
if field.blank?
|
59
|
+
relation.table[field_name]
|
60
|
+
elsif relation.reflections[table.to_sym]
|
61
|
+
relation.reflections[table.to_sym].klass.arel_table[field]
|
62
|
+
else
|
63
|
+
raise "Unable to find column for #{field_name}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
55
67
|
end
|
56
68
|
end
|
@@ -104,16 +104,15 @@ module TheGrid
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def may_assemble?(record, options)
|
107
|
-
|
107
|
+
column_or_proc = options[:if] || options[:unless]
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
result = true
|
109
|
+
result = true
|
110
|
+
if column_or_proc.is_a? Symbol
|
111
|
+
result = assemble_column_for(record, column_or_proc, columns[column_or_proc])
|
112
|
+
elsif column_or_proc.respond_to?(:call)
|
113
|
+
result = column_or_proc.call(record)
|
115
114
|
end
|
116
|
-
|
115
|
+
result.present? ^ options.has_key?(:unless)
|
117
116
|
end
|
118
117
|
|
119
118
|
end
|
data/lib/the_grid/version.rb
CHANGED
@@ -44,6 +44,16 @@ describe TheGrid::Api::Command::Filter do
|
|
44
44
|
|
45
45
|
after(:each) { subject.execute_on(relation, :filters => filters) }
|
46
46
|
|
47
|
+
context "when filters contain association's column" do
|
48
|
+
let(:filters){ { 'user.email' => 'test@i.ua' } }
|
49
|
+
|
50
|
+
it "filters by using correct columns" do
|
51
|
+
relation.stub_chain(:reflections, :[], :klass, :arel_table).and_return(table)
|
52
|
+
relation.reflections.should_receive(:[]).with(:user)
|
53
|
+
table.should_receive(:[]).with('email')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
47
57
|
context "when filters are missed" do
|
48
58
|
let(:filters){ Hash.new }
|
49
59
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergiy Stotskiy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.1.11
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Yet another grid api.
|