deep_pluck 0.1.3 → 0.1.4

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: b2fc03be65ab872d226258b31d8ae589f3fbcd5a
4
- data.tar.gz: e9509aff8cb651ac9f5cdc6589df4a392c1da44e
3
+ metadata.gz: 7dd60ee2a2873d438651509c33b1aad2e046c16c
4
+ data.tar.gz: b413505ee2ce1109174954377a7e99fb4bc4e4c3
5
5
  SHA512:
6
- metadata.gz: 23ac49792df4c092022648f7a7ae8bc1ca90f27f6bb743b29ed5f7648c1048ff20d41f6697e1bda4c12f87f59e5b122a515c409c3bade3d233f3a32fa2c4e156
7
- data.tar.gz: 4a470d307b03034676d5b16fdd2da2a13c52258e1403c6313e156ef58201f72e2f705679c35d8a98fe9ab711d9ad4273adf7c2e9b2a3767049460755fd6e28b5
6
+ metadata.gz: 93a7cd552701c578a624fae3823e588a2eb881f83d482536500228f3d0c9cdadc6e0177ba6b1023dcfa3e7ac03be124554c65e46a8993d1072f7c3335282fecf
7
+ data.tar.gz: ed86dcb371deac4a1b4603d0cfa7785797345c859b9e9b7d8d99ce36cc6d660565534ba99851074df7c0dc6a6a3305d454c08a4d813b5177e9f858e24c8edc59
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DeepPluck
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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-20 00:00:00.000000000 Z
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.6.8
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