active_record_content_blob 0.1.5 → 0.2.0
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 +8 -8
- data/VERSION +1 -1
- data/active_record_content_blob.gemspec +2 -2
- data/lib/content_blob/blobable.rb +9 -4
- data/spec/unit/blobable_spec.rb +21 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzAyNjgxZWQ0ODNhNzJhZDA5N2JkMDU5YjEwNmNmOTNmNTRjZWMwOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDEzYzNiMGQ1ZWEwYTI5YWNiYjk2YWVkYjUyMzFkM2Q3NzU0YjdmYg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTcxMDlkZjFhOWQ2MzIxYWFjNThlZjhjOGRiYTU4ZmI3MjQwYThhZjBiYjkx
|
10
|
+
YTllYzZmMjY5ODRjZDMyZTYyMDA1MjNhYmFkZWIzNGI0MzQ3YjA3MTQzYzAy
|
11
|
+
OTQwNTc4NjZiMmI1NDYzZGExOGM0OTcyN2U2MmMyOGRiMzE5MmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGI0MDMyYTZlNGI1MmM2YjExNGRiM2NiYTFmMDNjZjk5ZWJkMGFmOGYyNzNk
|
14
|
+
MGRhMTFiZjgyY2Q0MjQ2OGMwZGU5ZDQ4MjU5NWFkNDhhODdlYjFiYWMxZjlk
|
15
|
+
YmIyNGI0ZjM5N2UwYTI3YmFjNGRkYWRmN2ZmMTUzMWJjMDM4ZGQ=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "active_record_content_blob"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Nguyen"]
|
12
|
-
s.date = "2013-10-
|
12
|
+
s.date = "2013-10-25"
|
13
13
|
s.description = "Loading up TEXT/BLOB columns can be slow"
|
14
14
|
s.email = "dansonguyen@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,9 +42,7 @@ module ActiveRecordContentBlob
|
|
42
42
|
hsh
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
45
|
prepared_stuff = prepare_content_for_blob(stuff)
|
47
|
-
|
48
46
|
record.build_a_blob(prepared_stuff)
|
49
47
|
return record
|
50
48
|
end
|
@@ -63,14 +61,21 @@ module ActiveRecordContentBlob
|
|
63
61
|
end # classmethods
|
64
62
|
|
65
63
|
## instance methods
|
64
|
+
# First, see if blob exists
|
66
65
|
def build_a_blob(some_content)
|
67
|
-
|
66
|
+
if has_blob?
|
67
|
+
self.content_blob.assign_attributes(contents: some_content)
|
68
|
+
else
|
69
|
+
self.build_content_blob(contents: some_content)
|
70
|
+
end
|
71
|
+
|
72
|
+
self.content_blob
|
68
73
|
end
|
69
74
|
|
70
75
|
|
71
76
|
|
72
77
|
def has_blob?
|
73
|
-
content_blob.
|
78
|
+
!content_blob.nil?
|
74
79
|
end
|
75
80
|
|
76
81
|
|
data/spec/unit/blobable_spec.rb
CHANGED
@@ -32,17 +32,29 @@ describe "Blobable" do
|
|
32
32
|
expect(@record.contents).to eq({'abc' => 123})
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
context 'existing blobs' do
|
36
|
+
it 'should overwrite existing blob' do
|
37
|
+
@record.build_a_blob({'xyz'=>'999'})
|
38
|
+
expect(@record.content_blob.new_record?).to be_true
|
39
|
+
expect(@record.content_blob.valid?).to be_true
|
40
|
+
|
41
|
+
@record.save
|
42
|
+
|
43
|
+
@record = MusicRecord.find(@record.id)
|
44
|
+
expect(@record.contents['xyz']).to eq '999'
|
45
|
+
|
46
|
+
expect(ContentBlob.count).to eq 1
|
47
|
+
end
|
39
48
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
expect(@record.contents['xyz']).to eq '999'
|
49
|
+
it 'should keep same id of an existing blob' do
|
50
|
+
#ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base)
|
51
|
+
old_blob_id = @record.content_blob.id
|
44
52
|
|
45
|
-
|
53
|
+
@record.build_a_blob({'xyz'=>'999'})
|
54
|
+
@record.save
|
55
|
+
|
56
|
+
expect(old_blob_id).to eq @record.content_blob.id
|
57
|
+
end
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_content_blob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|