active_hash_relation 0.0.3 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e8a15147af3c9b53fa1edadbd8a6d73c1032dfa
|
4
|
+
data.tar.gz: caa04edc9050cd929d30ca023004c34618b6316c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a37b985fbebea7efd854ac282a60308b62ac67d994fdc2f204d4bfdc06c1e328b749126b4e952c40220e200718bbb53eda434d2aa734c499121ba251493f61ab
|
7
|
+
data.tar.gz: 2ae6c59dacc4aafe54b4eb441b38b17434a2986aa6e9fe9be7f4493ff5e4d1d7067ec45306e09d6b8f24e2e70a9f7abe5821073b94e1f8350e97122ff9aa2115
|
data/README.md
CHANGED
@@ -21,9 +21,9 @@ underneath with the same params.
|
|
21
21
|
_\*Actually nothing is exposed, but a user could retrieve resources based
|
22
22
|
on unknown attributes (attributes not returned from the API) by brute forcing
|
23
23
|
which might or might not be a security issue. If you don't like that check
|
24
|
-
[whitelisting](
|
24
|
+
[whitelisting](#whitelisting)._
|
25
25
|
|
26
|
-
*New*! You can now do [__aggregation queries__](
|
26
|
+
*New*! You can now do [__aggregation queries__](#aggregation-queries).
|
27
27
|
|
28
28
|
## Installation
|
29
29
|
|
@@ -149,7 +149,7 @@ called to apply the filters in resource association.
|
|
149
149
|
Sometimes we need to ask the database queries that act on the collection but don't want back an array of elements but a value instead! Now you can do that on an ActiveRecord::Relation by simply calling the aggregations method inside the controller:
|
150
150
|
|
151
151
|
```ruby
|
152
|
-
|
152
|
+
aggregations(resource, {
|
153
153
|
aggregate: {
|
154
154
|
integer_column: { avg: true, max: true, min: true, sum: true },
|
155
155
|
float_column: {avg: true, max: true, min: true },
|
@@ -165,7 +165,7 @@ and you will get a hash (HashWithIndifferentAccess) back that holds all your agg
|
|
165
165
|
"datetime_at"=>{"max"=>2015-06-11 20:59:14 UTC, "min"=>2015-06-11 20:59:12 UTC}}
|
166
166
|
```
|
167
167
|
|
168
|
-
These attributes usually go to the "meta" section of your serializer. In that way it's easy to parse them in the front-end (for ember check [here](http://guides.emberjs.com/v1.10.0/models/handling-metadata/). Please note that you should apply the aggregations __after__ you apply the filters
|
168
|
+
These attributes usually go to the "meta" section of your serializer. In that way it's easy to parse them in the front-end (for ember check [here](http://guides.emberjs.com/v1.10.0/models/handling-metadata/)). Please note that you should apply the aggregations __after__ you apply the filters (if there any) but __before__ you apply pagination!
|
169
169
|
|
170
170
|
|
171
171
|
|
@@ -46,7 +46,7 @@ module ActiveHashRelation
|
|
46
46
|
meta_attributes = HashWithIndifferentAccess.new
|
47
47
|
|
48
48
|
available_aggr.each do |k, v|
|
49
|
-
if asked_aggr[k]
|
49
|
+
if asked_aggr[k]
|
50
50
|
meta_attributes[k] = resource.send(v,column)
|
51
51
|
meta_attributes[k] = meta_attributes[k].to_f if meta_attributes[k].is_a? BigDecimal
|
52
52
|
end
|
@@ -56,15 +56,15 @@ module ActiveHashRelation::ColumnFilters
|
|
56
56
|
private
|
57
57
|
|
58
58
|
def apply_leq_geq_le_ge_filters(resource, table_name, column, param)
|
59
|
-
if param[:leq]
|
59
|
+
if !param[:leq].blank?
|
60
60
|
resource = resource.where("#{table_name}.#{column} <= ?", param[:leq])
|
61
|
-
elsif param[:le]
|
61
|
+
elsif !param[:le].blank?
|
62
62
|
resource = resource.where("#{table_name}.#{column} < ?", param[:le])
|
63
63
|
end
|
64
64
|
|
65
|
-
if param[:geq]
|
65
|
+
if !param[:geq].blank?
|
66
66
|
resource = resource.where("#{table_name}.#{column} >= ?", param[:geq])
|
67
|
-
elsif param[:ge]
|
67
|
+
elsif !param[:ge].blank?
|
68
68
|
resource = resource.where("#{table_name}.#{column} > ?", param[:ge])
|
69
69
|
end
|
70
70
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_hash_relation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filippos Vasilakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.4.
|
86
|
+
rubygems_version: 2.4.8
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Simple gem that allows you to run multiple ActiveRecord::Relation using hash.
|