columns_on_demand 5.1.1 → 5.1.2

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: 11669dc2b1270745b3daf5f0b4edd68a711edc45
4
- data.tar.gz: 7e221c815f656f81f225fe0052c1acb22d4346dd
3
+ metadata.gz: a81ff04523e371ffc1da7110c2044fd3f4e02639
4
+ data.tar.gz: e139bc9d3ee903d15985e475d1e7d235c19c3a89
5
5
  SHA512:
6
- metadata.gz: 1ce9b3fb616787002fa71b58c4dbc71a7d00795f2ac7c0cfd905326bcc32b0f444664b6e529488c8799d5054f5a78076f159f28b7b21130559cb8848dc92a58e
7
- data.tar.gz: 31f75591d087e6e4e448c36ba99ebd8fd2ce186af13f7067f67bf2bef6fa5909d6b8b943214236f346ba36eff25f8708a9d772c066feb2006fcc05f142fafcc9
6
+ metadata.gz: 52869db49b76dc76722cdbe4a513f35d83cfb4f07da435c10ed1a7cf9b482ad0d6766087c3783eea97caf109b8dc4be1c02348eaad08e3af3c3095e18dedc1fb
7
+ data.tar.gz: b28d0a071c5d8826f82834191de82fd527574b372b89ca8e8ca9960c2b63e211656e62ad9c4657ca8854d6fed7bda62c8fdd6373a8356c8fcf2b9d325499c232
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Declare your gem's dependencies in transaction_isolation_level.gemspec.
3
+ # Declare your gem's dependencies in columns_on_demand.gemspec.
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
5
5
  # development dependencies will be added by default to the :development group.
6
6
  gemspec
@@ -11,4 +11,3 @@ gemspec
11
11
  # your gem to rubygems.org.
12
12
 
13
13
  gem 'rails', ENV['RAILS_VERSION']
14
- gem 'nokogiri', '~> 1.6.7.2'
data/README.md CHANGED
@@ -21,7 +21,7 @@ Compatibility
21
21
 
22
22
  Supports mysql, mysql2, postgresql, and sqlite3.
23
23
 
24
- Currently tested against Rails 5.1 (up to 5.1.0beta1), 5.0 (up to 5.0.2), and 4.2 (up to 4.2.7), on Ruby 2.3.4.
24
+ Currently tested against Rails 5.1 (up to 5.1.4), 5.0 (up to 5.0.6), and 4.2 (up to 4.2.10), on Ruby 2.3.4.
25
25
 
26
26
  For earlier versions of Rails, use an older version of the gem.
27
27
 
@@ -54,4 +54,4 @@ Thanks
54
54
  * Tobias Matthies (@tobmatth)
55
55
  * Phil Ross (@philr)
56
56
 
57
- Copyright (c) 2008-2015 Will Bryant, Sekuda Ltd, released under the MIT license
57
+ Copyright (c) 2008-2017 Will Bryant, Sekuda Ltd, released under the MIT license
@@ -14,7 +14,7 @@ module ColumnsOnDemand
14
14
  end
15
15
 
16
16
  def reset_column_information_with_columns_on_demand
17
- @columns_to_select = nil
17
+ @columns_to_select = @columns_to_load_by_default = nil
18
18
  reset_column_information_without_columns_on_demand
19
19
  end
20
20
 
@@ -29,13 +29,17 @@ module ColumnsOnDemand
29
29
  module ClassMethods
30
30
  # this is the method API as called by ActiveRecord 2.x. we also call it ourselves above in our ActiveRecord 3 extensions.
31
31
  def default_select(qualified)
32
- @columns_to_select ||= (columns.collect(&:name) - columns_to_load_on_demand).collect {|attr_name| connection.quote_column_name(attr_name)}
32
+ @columns_to_select ||= columns_to_load_by_default.collect {|attr_name| connection.quote_column_name(attr_name)}
33
33
  if qualified
34
34
  quoted_table_name + '.' + @columns_to_select.join(", #{quoted_table_name}.")
35
35
  else
36
36
  @columns_to_select.join(", ")
37
37
  end
38
38
  end
39
+
40
+ def columns_to_load_by_default
41
+ @columns_to_load_by_default ||= Set.new(columns.collect(&:name) - columns_to_load_on_demand)
42
+ end
39
43
  end
40
44
 
41
45
  module InstanceMethods
@@ -48,7 +52,11 @@ module ColumnsOnDemand
48
52
  end
49
53
 
50
54
  def attributes
51
- load_attributes(*columns_to_load_on_demand.reject {|attr_name| column_loaded?(attr_name)})
55
+ loaded_attributes = @attributes.keys
56
+ if loaded_attributes.size == self.class.columns_to_load_by_default.size &&
57
+ loaded_attributes.size == (self.class.columns_to_load_by_default & loaded_attributes).size
58
+ load_attributes(*columns_to_load_on_demand.reject {|attr_name| column_loaded?(attr_name)})
59
+ end
52
60
  super
53
61
  end
54
62
 
@@ -1,3 +1,3 @@
1
1
  module ColumnsOnDemand
2
- VERSION = '5.1.1'
2
+ VERSION = '5.1.2'
3
3
  end
@@ -136,6 +136,18 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
136
136
  assert !attributes["processing_log"].blank?
137
137
  end
138
138
  end
139
+
140
+ test "it doesn't load the column when generating #attributes if not included in the select() list" do
141
+ attributes = Implicit.select("id, original_filename").first.attributes
142
+ assert_equal "somefile.txt", attributes["original_filename"]
143
+ assert !attributes.has_key?("file_data")
144
+ end
145
+
146
+ test "it loads the column when generating #attributes if included in the select() list" do
147
+ attributes = Implicit.select("id, original_filename, file_data").first.attributes
148
+ assert_equal "somefile.txt", attributes["original_filename"]
149
+ assert_equal "This is the file data!", attributes["file_data"]
150
+ end
139
151
 
140
152
  test "it loads the column when generating #to_json" do
141
153
  ActiveRecord::Base.include_root_in_json = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: columns_on_demand
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Bryant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord