active_hash_relation 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/README.md +16 -0
- data/lib/active_hash_relation/association_filters.rb +1 -1
- data/lib/active_hash_relation/filter_applier.rb +2 -2
- data/lib/active_hash_relation/scope_filters.rb +1 -1
- data/lib/active_hash_relation/version.rb +1 -1
- data/lib/active_hash_relation.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b6475c5d16eab20007e41f124b9db329cc9788a
|
4
|
+
data.tar.gz: 256afb180075bb73703f59bd5496aa4af6225f0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6edc4a82cbd60e9f459d6490d09086ec7f224f9bc346555972b848bb6b4a2417e181a9b136c21699bbe48d90ac7608f201d9f2e6bb7a31be5836fd03a477aec2
|
7
|
+
data.tar.gz: f9ed814d95540090b83f7aa744583ffd655884784587442f0fe691f2866503197c2da359f638130e129e9448c1a3948594284121749411f73f91543103926d8b
|
data/README.md
CHANGED
@@ -123,6 +123,22 @@ Scopes are supported via a tiny monkeypatch in the ActiveRecord's scope class me
|
|
123
123
|
|
124
124
|
will run the `.planned` scope on the resource.
|
125
125
|
|
126
|
+
### Unscoped assotiations
|
127
|
+
If you have a default scope in your models and you have a good reason to keep that, `active_hash_relation` provides an option to override it when filtering associations:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
#config/initializers/active_hash_relation.rb
|
131
|
+
ActiveHashRelation.configure do |config|
|
132
|
+
config.use_unscoped = true
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
You still have to provide the main model `active_hash_relation` runs as unscoped though.
|
137
|
+
```ruby
|
138
|
+
apply_filters(Video.unscoped.all, {limit: 30, user: {country_code: 'SE'}})
|
139
|
+
#"SELECT \"videos\".* FROM \"videos\" INNER JOIN \"users\" ON \"users\".\"id\" = \"videos\".\"user_id\" WHERE (users.country_code ILIKE '%GR%') LIMIT 30"
|
140
|
+
```
|
141
|
+
|
126
142
|
### Whitelisting
|
127
143
|
If you don't want to allow a column/association/scope just remove it from the params hash.
|
128
144
|
|
@@ -58,8 +58,8 @@ module ActiveHashRelation
|
|
58
58
|
end
|
59
59
|
|
60
60
|
|
61
|
-
@resource = filter_scopes(@resource, @params[:scopes]) if @params.include?(:scopes)
|
62
|
-
@resource = filter_associations(@resource, @params) if @include_associations
|
61
|
+
@resource = filter_scopes(@resource, @params[:scopes], @model) if @params.include?(:scopes)
|
62
|
+
@resource = filter_associations(@resource, @params, @model) if @include_associations
|
63
63
|
@resource = apply_limit(@resource, @params[:limit]) if @params.include?(:limit)
|
64
64
|
@resource = apply_sort(@resource, @params[:sort], @model) if @params.include?(:sort)
|
65
65
|
|
data/lib/active_hash_relation.rb
CHANGED
@@ -35,8 +35,8 @@ module ActiveHashRelation
|
|
35
35
|
).apply_filters
|
36
36
|
end
|
37
37
|
|
38
|
-
def aggregations(resource, params)
|
39
|
-
Aggregation.new(resource, params).apply
|
38
|
+
def aggregations(resource, params, model: nil)
|
39
|
+
Aggregation.new(resource, params, model: model).apply
|
40
40
|
end
|
41
41
|
|
42
42
|
class Configuration
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_hash_relation
|
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
|
- Filippos Vasilakis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|