activerecord_lax_includes 0.1.1 → 0.1.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a077f03322432709f78b6200f74607a86143307c
4
+ data.tar.gz: 26932f8326062d19e6c0799d95d745c5d921905a
5
+ SHA512:
6
+ metadata.gz: 5e05c126fa6f00dd993d553dbf318dda6f7610c8cd3a301a4677d970f164603f8c840546aa68fac1a4299c3ecde59eed671af88f4f692eefd5ac2fa3490b573d
7
+ data.tar.gz: 87f7adde3b79f6aeb1a622bfb81b5fe7e6a14a3d1620aef04d410e8d1be968c914776563f7f92290750a2c76ff9b974b7270ea8d1094cbbc4d361a416f4a3127
@@ -4,12 +4,29 @@ module ActiveRecordLaxIncludes
4
4
  base.class_eval do
5
5
  alias_method :records_by_reflection_default, :records_by_reflection
6
6
  alias_method :records_by_reflection, :records_by_reflection_with_lax_include
7
+
8
+ alias_method :preload_hash_default, :preload_hash
9
+ alias_method :preload_hash, :preload_hash_with_lax_include
10
+ end
11
+ end
12
+
13
+ def preload_hash_with_lax_include(association)
14
+ if lax_includes_enabled?
15
+ association.each do |parent, child|
16
+ ActiveRecord::Associations::Preloader.new(records, parent, options).run
17
+ associated_records = filtered_records_by_reflection(parent).map { |record| record.send(parent) }.flatten
18
+ ActiveRecord::Associations::Preloader.new(associated_records, child).run
19
+ end
20
+ else
21
+ preload_hash_default(association)
7
22
  end
8
23
  end
9
24
 
10
25
  def records_by_reflection_with_lax_include(association)
11
26
  if lax_includes_enabled?
12
- filtered_records_by_reflection(association)
27
+ filtered_records_by_reflection(association).group_by do |record|
28
+ record.class.reflections[association]
29
+ end
13
30
  else
14
31
  records_by_reflection_default(association)
15
32
  end
@@ -18,13 +35,16 @@ module ActiveRecordLaxIncludes
18
35
  def filtered_records_by_reflection(association)
19
36
  records.select do |record|
20
37
  record.class.reflections[association].present?
21
- end.group_by do |record|
22
- record.class.reflections[association]
23
38
  end
24
39
  end
25
40
 
26
41
  def lax_includes_enabled?
27
- !!Thread.current[:active_record_lax_includes_enabled]
42
+ result = Thread.current[:active_record_lax_includes_enabled]
43
+ if result.nil?
44
+ result = Rails.configuration.respond_to?(:active_record_lax_includes_enabled) &&
45
+ Rails.configuration.active_record_lax_includes_enabled
46
+ end
47
+ result
28
48
  end
29
49
  end
30
50
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_lax_includes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Charles Barbier
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description:
15
14
  email: unixcharles@gmail.com
@@ -17,31 +16,30 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - README.md
21
19
  - LICENSE
20
+ - README.md
22
21
  - lib/activerecord_lax_includes.rb
23
22
  homepage: http://github.com/unixcharles/active-record-lax-includes
24
23
  licenses: []
24
+ metadata: {}
25
25
  post_install_message:
26
26
  rdoc_options: []
27
27
  require_paths:
28
28
  - lib
29
29
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
30
  requirements:
32
- - - ! '>='
31
+ - - ">="
33
32
  - !ruby/object:Gem::Version
34
33
  version: '0'
35
34
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
35
  requirements:
38
- - - ! '>='
36
+ - - ">="
39
37
  - !ruby/object:Gem::Version
40
38
  version: '0'
41
39
  requirements: []
42
40
  rubyforge_project:
43
- rubygems_version: 1.8.24
41
+ rubygems_version: 2.2.0
44
42
  signing_key:
45
- specification_version: 3
43
+ specification_version: 4
46
44
  summary: Hotfix nested eager loading for polymorphic and STI relation in ActiveRecord
47
45
  test_files: []