columns_on_demand 5.2.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/Gemfile +1 -0
- data/README.md +3 -4
- data/columns_on_demand.gemspec +0 -9
- data/lib/columns_on_demand/version.rb +1 -1
- data/lib/columns_on_demand.rb +18 -0
- data/test/columns_on_demand_test.rb +25 -4
- data/test/database.yml +0 -2
- data/test/test_helper.rb +7 -2
- data/test_all.sh +3 -3
- metadata +7 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1e6e04d64f6f526080014087994ae0a6ec5b0561fcf02b25cedbf425ca78b77
|
4
|
+
data.tar.gz: 25cc43696bb8a5e93650bf95e02143e4071006566e59bdb690c1a1d870b69994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64411dd375053f0bdbbe6806faa08500c6d774b6093717504456192c4b9751a560a3f9ca63a15c772a6da86015fb31c6f9da1c69cf392ad736aabf0a5f1b56a6
|
7
|
+
data.tar.gz: 0d07cb102b4a5ac022bd8afa71cb6c1e3d261a23da004a668c23c208b67090fd064f843874099559f526582b40bd3edadf5cfc0e6323230d33c1cfe1d9854451
|
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
dist: bionic
|
6
|
+
rvm:
|
7
|
+
- 2.6
|
8
|
+
services:
|
9
|
+
- postgresql
|
10
|
+
- mysql
|
11
|
+
before_script:
|
12
|
+
- createdb -U postgres columns_on_demand_test
|
13
|
+
- mysqladmin -u root create columns_on_demand_test
|
14
|
+
script: ./test_all.sh
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -21,9 +21,7 @@ Compatibility
|
|
21
21
|
|
22
22
|
Supports mysql, mysql2, postgresql, and sqlite3.
|
23
23
|
|
24
|
-
Currently tested against Rails
|
25
|
-
|
26
|
-
For earlier versions of Rails, use an older version of the gem.
|
24
|
+
Currently tested against Rails 7.2.0.beta2, 7.1.3.4, 7.0.8.4, and 6.1.7.8, with older gem versions compatible with earlier Rails versions.
|
27
25
|
|
28
26
|
|
29
27
|
Example
|
@@ -53,5 +51,6 @@ Thanks
|
|
53
51
|
* Tim Connor (@tlconnor)
|
54
52
|
* Tobias Matthies (@tobmatth)
|
55
53
|
* Phil Ross (@philr)
|
54
|
+
* Jens Schmidt (@w3dot0)
|
56
55
|
|
57
|
-
Copyright (c) 2008-
|
56
|
+
Copyright (c) 2008-2024 Will Bryant, Sekuda Ltd, released under the MIT license
|
data/columns_on_demand.gemspec
CHANGED
@@ -19,16 +19,7 @@ pages since they are not stored wholly in the record's page itself.
|
|
19
19
|
|
20
20
|
Although this plugin is mainly used for BLOB and TEXT columns, it will actually
|
21
21
|
work on all types - and is just as useful for large string fields etc.
|
22
|
-
|
23
|
-
|
24
|
-
Compatibility
|
25
|
-
=============
|
26
|
-
|
27
|
-
Supports mysql, mysql2, postgresql, and sqlite3.
|
28
|
-
|
29
|
-
Currently tested against Rails 3.2.18, 4.0.8, and 4.1.4, on Ruby 2.0.0.
|
30
22
|
EOF
|
31
|
-
gem.has_rdoc = false
|
32
23
|
gem.author = "Will Bryant"
|
33
24
|
gem.email = "will.bryant@gmail.com"
|
34
25
|
gem.homepage = "http://github.com/willbryant/columns_on_demand"
|
data/lib/columns_on_demand.rb
CHANGED
@@ -63,6 +63,14 @@ module ColumnsOnDemand
|
|
63
63
|
def attribute_names
|
64
64
|
(super + columns_to_load_on_demand).uniq.sort
|
65
65
|
end
|
66
|
+
|
67
|
+
def attribute_method?(attr_name)
|
68
|
+
super || columns_to_load_on_demand.include?(attr_name)
|
69
|
+
end
|
70
|
+
|
71
|
+
def _has_attribute?(attr_name)
|
72
|
+
super || columns_to_load_on_demand.include?(attr_name)
|
73
|
+
end
|
66
74
|
|
67
75
|
def load_attributes(*attr_names)
|
68
76
|
return if attr_names.blank?
|
@@ -107,6 +115,16 @@ module ColumnsOnDemand
|
|
107
115
|
super(attr_name, &block)
|
108
116
|
end
|
109
117
|
|
118
|
+
def write_attribute(attr_name, value)
|
119
|
+
ensure_loaded(attr_name)
|
120
|
+
super(attr_name, value)
|
121
|
+
end
|
122
|
+
|
123
|
+
def _write_attribute(attr_name, value)
|
124
|
+
ensure_loaded(attr_name)
|
125
|
+
super(attr_name, value)
|
126
|
+
end
|
127
|
+
|
110
128
|
def missing_attribute(attr_name, *args)
|
111
129
|
if columns_to_load_on_demand.include?(attr_name)
|
112
130
|
load_attributes(attr_name)
|
@@ -148,6 +148,13 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
|
|
148
148
|
assert_equal "somefile.txt", attributes["original_filename"]
|
149
149
|
assert_equal "This is the file data!", attributes["file_data"]
|
150
150
|
end
|
151
|
+
|
152
|
+
test "it loads the column when changing its value" do
|
153
|
+
record = Implicit.first
|
154
|
+
record.file_data = 'This is the new file data!'
|
155
|
+
assert_equal "This is the file data!", record.file_data_was
|
156
|
+
assert_equal ["This is the file data!", "This is the new file data!"], record.changes[:file_data]
|
157
|
+
end
|
151
158
|
|
152
159
|
test "it loads the column when generating #to_json" do
|
153
160
|
ActiveRecord::Base.include_root_in_json = true
|
@@ -177,7 +184,8 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
|
|
177
184
|
|
178
185
|
test "it does not think the column has been loaded if a reloaded instance that has not loaded the attribute is saved" do
|
179
186
|
record = Implicit.first
|
180
|
-
record.
|
187
|
+
record.file_data = "New file data"
|
188
|
+
record.save!
|
181
189
|
|
182
190
|
record.reload
|
183
191
|
record.save!
|
@@ -187,7 +195,8 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
|
|
187
195
|
|
188
196
|
test "it does not think the column has been loaded if a fresh instance that has not loaded the attribute is saved" do
|
189
197
|
record = Implicit.first
|
190
|
-
record.
|
198
|
+
record.file_data = "New file data"
|
199
|
+
record.save!
|
191
200
|
|
192
201
|
record = Implicit.find(record.id)
|
193
202
|
record.save!
|
@@ -230,6 +239,18 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
|
|
230
239
|
|
231
240
|
assert_equal "This is the file data!", record.file_data # check it doesn't raise
|
232
241
|
end
|
242
|
+
|
243
|
+
test "it reports the columns in the class-level attribute_method?" do
|
244
|
+
assert(Implicit.attribute_method?("file_data"))
|
245
|
+
end
|
246
|
+
|
247
|
+
test "it reports the columns in the instance-level attribute_method?" do
|
248
|
+
assert(Implicit.first.send(:attribute_method?, "file_data"))
|
249
|
+
end
|
250
|
+
|
251
|
+
test "it makes the instance classes respond_to the attribute even if not loaded" do
|
252
|
+
assert(Implicit.first.respond_to?(:file_data))
|
253
|
+
end
|
233
254
|
|
234
255
|
test "it handles STI models" do
|
235
256
|
class Sti < ActiveRecord::Base
|
@@ -281,9 +302,9 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
|
|
281
302
|
|
282
303
|
assert !ValidatedImplicit.new(:original_filename => "test.txt").valid?
|
283
304
|
instance = ValidatedImplicit.create!(:original_filename => "test.txt", :file_data => "test file data", :results => "test results")
|
284
|
-
instance.
|
305
|
+
assert instance.valid? # file_data and results are already loaded
|
285
306
|
new_instance = ValidatedImplicit.find(instance.id)
|
286
|
-
new_instance.
|
307
|
+
assert new_instance.valid? # file_data and results aren't loaded yet, but will be loaded to validate
|
287
308
|
end
|
288
309
|
|
289
310
|
test "it works with serialized columns" do
|
data/test/database.yml
CHANGED
data/test/test_helper.rb
CHANGED
@@ -23,11 +23,16 @@ rescue LoadError
|
|
23
23
|
end
|
24
24
|
|
25
25
|
ActiveRecord::Base.configurations = YAML::load(IO.read(File.join(File.dirname(__FILE__), "database.yml")))
|
26
|
-
configuration = ActiveRecord::Base.configurations
|
26
|
+
configuration = ActiveRecord::Base.configurations.find_db_config(ENV['RAILS_ENV'])
|
27
27
|
raise "use RAILS_ENV=#{ActiveRecord::Base.configurations.keys.sort.join '/'} to test this plugin" unless configuration
|
28
28
|
ActiveRecord::Base.establish_connection configuration
|
29
29
|
|
30
30
|
ActiveSupport::TestCase.send(:include, ActiveRecord::TestFixtures) if ActiveRecord.const_defined?('TestFixtures')
|
31
|
-
|
31
|
+
|
32
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_paths)
|
33
|
+
ActiveSupport::TestCase.fixture_paths = [File.join(File.dirname(__FILE__), "fixtures")]
|
34
|
+
else
|
35
|
+
ActiveSupport::TestCase.fixture_path = File.join(File.dirname(__FILE__), "fixtures")
|
36
|
+
end
|
32
37
|
|
33
38
|
require File.expand_path(File.join(File.dirname(__FILE__), '../init')) # load columns_on_demand
|
data/test_all.sh
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
set -e
|
4
4
|
|
5
|
-
for version in
|
5
|
+
for version in 6.1.7.8 7.0.8.4 7.1.3.4 7.2.0.beta2
|
6
6
|
do
|
7
|
-
RAILS_VERSION=$version bundle update rails
|
7
|
+
RAILS_VERSION=$version SQLITE3_VERSION=1.5.0 bundle update rails sqlite3
|
8
8
|
RAILS_ENV=sqlite3 bundle exec rake
|
9
9
|
RAILS_ENV=postgresql bundle exec rake
|
10
10
|
RAILS_ENV=mysql2 bundle exec rake
|
11
|
-
done
|
11
|
+
done
|
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:
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,20 +108,13 @@ description: |
|
|
108
108
|
|
109
109
|
Although this plugin is mainly used for BLOB and TEXT columns, it will actually
|
110
110
|
work on all types - and is just as useful for large string fields etc.
|
111
|
-
|
112
|
-
|
113
|
-
Compatibility
|
114
|
-
=============
|
115
|
-
|
116
|
-
Supports mysql, mysql2, postgresql, and sqlite3.
|
117
|
-
|
118
|
-
Currently tested against Rails 3.2.18, 4.0.8, and 4.1.4, on Ruby 2.0.0.
|
119
111
|
email: will.bryant@gmail.com
|
120
112
|
executables: []
|
121
113
|
extensions: []
|
122
114
|
extra_rdoc_files: []
|
123
115
|
files:
|
124
116
|
- ".gitignore"
|
117
|
+
- ".travis.yml"
|
125
118
|
- Gemfile
|
126
119
|
- MIT-LICENSE
|
127
120
|
- README.md
|
@@ -143,7 +136,7 @@ homepage: http://github.com/willbryant/columns_on_demand
|
|
143
136
|
licenses:
|
144
137
|
- MIT
|
145
138
|
metadata: {}
|
146
|
-
post_install_message:
|
139
|
+
post_install_message:
|
147
140
|
rdoc_options: []
|
148
141
|
require_paths:
|
149
142
|
- lib
|
@@ -158,9 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
151
|
- !ruby/object:Gem::Version
|
159
152
|
version: '0'
|
160
153
|
requirements: []
|
161
|
-
|
162
|
-
|
163
|
-
signing_key:
|
154
|
+
rubygems_version: 3.3.26
|
155
|
+
signing_key:
|
164
156
|
specification_version: 4
|
165
157
|
summary: Lazily loads large columns on demand.
|
166
158
|
test_files:
|