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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjdmMjg5N2E0ZTA1ZDAzZWUxYTFhM2YxZTUzNjgzZjRlNjdlNWFiNA==
4
+ MzAyNjgxZWQ0ODNhNzJhZDA5N2JkMDU5YjEwNmNmOTNmNTRjZWMwOA==
5
5
  data.tar.gz: !binary |-
6
- NzA3YmRmMDQ1YWVlZjhlNDkwMGRlZTk1ZDE3MDlhZDE2OWUxMjk5Ng==
6
+ MDEzYzNiMGQ1ZWEwYTI5YWNiYjk2YWVkYjUyMzFkM2Q3NzU0YjdmYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjgwNTcwZDZhOGY4NzcxODY5NTAyZjk2MTRlN2ZiMjg2MWQ4MGY5MTRlZGUx
10
- NjNkYjVjN2VmMGExMTc4OGQ5MDA3NGJjMDRjOTgyOGNiZTc4YzkyOWE5ZmU2
11
- MTMzNzYwOTM5ZjE5YWIxMjc1MDM4ZGZlMjBhNmMxNGM5NThkOTQ=
9
+ YTcxMDlkZjFhOWQ2MzIxYWFjNThlZjhjOGRiYTU4ZmI3MjQwYThhZjBiYjkx
10
+ YTllYzZmMjY5ODRjZDMyZTYyMDA1MjNhYmFkZWIzNGI0MzQ3YjA3MTQzYzAy
11
+ OTQwNTc4NjZiMmI1NDYzZGExOGM0OTcyN2U2MmMyOGRiMzE5MmE=
12
12
  data.tar.gz: !binary |-
13
- ZGYyYjFlYTZhNjg0NTA3MjQwMjcyNzBjMjFkZDUwYWFkNGU2NzAyMWUwNzRm
14
- MDVlYWM4MGM5ZWEwNjg2MmUxYzAxN2ZiMTQzOGJjMGYxMDNlOTRkNWY0ODcx
15
- NGJmMzNiN2UxMzgwNTA3NmY0YmM0MmMyODgxYTg5ZjRjNTJjNTE=
13
+ ZGI0MDMyYTZlNGI1MmM2YjExNGRiM2NiYTFmMDNjZjk5ZWJkMGFmOGYyNzNk
14
+ MGRhMTFiZjgyY2Q0MjQ2OGMwZGU5ZDQ4MjU5NWFkNDhhODdlYjFiYWMxZjlk
15
+ YmIyNGI0ZjM5N2UwYTI3YmFjNGRkYWRmN2ZmMTUzMWJjMDM4ZGQ=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
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.1.5"
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-13"
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
- self.build_content_blob(contents: some_content)
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.exists?
78
+ !content_blob.nil?
74
79
  end
75
80
 
76
81
 
@@ -32,17 +32,29 @@ describe "Blobable" do
32
32
  expect(@record.contents).to eq({'abc' => 123})
33
33
  end
34
34
 
35
- it 'should overwrite existing blob' do
36
- @record.build_a_blob({'xyz'=>'999'})
37
- expect(@record.content_blob.new_record?).to be_true
38
- expect(@record.content_blob.valid?).to be_true
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
- @record.save
41
-
42
- @record = MusicRecord.find(@record.id)
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
- expect(ContentBlob.count).to eq 1
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.1.5
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-13 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3