deep_pluck 0.1.3 → 0.1.4
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/lib/deep_pluck/model.rb +7 -0
- data/lib/deep_pluck/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd60ee2a2873d438651509c33b1aad2e046c16c
|
4
|
+
data.tar.gz: b413505ee2ce1109174954377a7e99fb4bc4e4c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93a7cd552701c578a624fae3823e588a2eb881f83d482536500228f3d0c9cdadc6e0177ba6b1023dcfa3e7ac03be124554c65e46a8993d1072f7c3335282fecf
|
7
|
+
data.tar.gz: ed86dcb371deac4a1b4603d0cfa7785797345c859b9e9b7d8d99ce36cc6d660565534ba99851074df7c0dc6a6a3305d454c08a4d813b5177e9f858e24c8edc59
|
data/lib/deep_pluck/model.rb
CHANGED
@@ -17,6 +17,12 @@ module DeepPluck
|
|
17
17
|
@relation.klass.reflect_on_association(association_key.to_sym) || #add to_sym since rails 3 only support symbol
|
18
18
|
raise(ActiveRecord::ConfigurationError, "ActiveRecord::ConfigurationError: Association named '#{association_key}' was not found on #{@relation.klass.name}; perhaps you misspelled it?")
|
19
19
|
end
|
20
|
+
def with_conditions(reflect, relation)
|
21
|
+
options = reflect.options
|
22
|
+
relation = relation.instance_exec(&reflect.scope) if reflect.respond_to?(:scope) and reflect.scope
|
23
|
+
relation = relation.where(options[:conditions]) if options[:conditions]
|
24
|
+
return relation
|
25
|
+
end
|
20
26
|
def get_join_table(reflect, bool_flag = false)
|
21
27
|
return reflect.options[:through] if reflect.options[:through]
|
22
28
|
return (reflect.options[:join_table] || reflect.send(:derive_join_table)) if reflect.macro == :has_and_belongs_to_many
|
@@ -71,6 +77,7 @@ module DeepPluck
|
|
71
77
|
ids = parent.map{|s| s[parent_key]}
|
72
78
|
ids.uniq!
|
73
79
|
ids.compact!
|
80
|
+
relation = with_conditions(reflect, relation)
|
74
81
|
return relation.joins(get_join_table(reflect)).where(relation_key => ids)
|
75
82
|
end
|
76
83
|
private
|
data/lib/deep_pluck/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_pluck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.4.8
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Use deep_pluck as a shortcut to select one or more attributes and include
|