dis 1.0.5 → 1.0.6

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b2fd660ff2a6498b73046ce44d262e49440e48e
4
- data.tar.gz: 9008b0cd219133671c8910dc5353b3a2fe665a0d
3
+ metadata.gz: 769e16af4437ba86e74fcae272a4e7d893737cc1
4
+ data.tar.gz: 64330af5cd3172d8f94804391bbbab85c8f87435
5
5
  SHA512:
6
- metadata.gz: 98d5e2fe6406b2549902eff4ce453e747b16dae2da095feffef8c66f0b0ec454d94004d2ee0045de5915f01efed958c60d0c5f7cd23b527123c06cfe03ac7a28
7
- data.tar.gz: 1ac6bbf53d47be0dfaf54b2be0cc596389eacb9f8cde4a42a98c77d3fa8de15b85bef305c85b08af30443836827e418409e043fbbbfb54eb580f1bfeb759a4d4
6
+ metadata.gz: 361ec8faf76e47ba5bb8185e4d34ea8f30667d395aee2530cf4956e021d3925d8f8196228506bfaa0080ef0a60d429f6915ceb67560be8cdde61e689749f3eb7
7
+ data.tar.gz: 0edc37ad592b0c61c01ff984b801e954472913b716d74d78f1556cfb23845d78600c64d0a925a8cd53cd205f582e52e6cf66a993677df93901111da0f33a432e
@@ -100,11 +100,15 @@ module Dis
100
100
 
101
101
  # Assigns new data. This also sets <tt>content_length</tt>, and resets
102
102
  # <tt>content_hash</tt> to nil.
103
- def data=(new_data)
104
- new_data = Dis::Model::Data.new(self, new_data)
103
+ def data=(raw_data)
104
+ new_data = Dis::Model::Data.new(self, raw_data)
105
105
  attribute_will_change!('data') unless new_data == dis_data
106
106
  @dis_data = new_data
107
- dis_set :content_hash, nil
107
+ dis_set :content_hash, if raw_data.nil?
108
+ nil
109
+ else
110
+ Storage.file_digest(new_data.read)
111
+ end
108
112
  dis_set :content_length, dis_data.content_length
109
113
  end
110
114
 
@@ -113,6 +117,10 @@ module Dis
113
117
  changes.include?('data')
114
118
  end
115
119
 
120
+ def dis_stored?
121
+ !(new_record? || data_changed?)
122
+ end
123
+
116
124
  # Assigns new data from an uploaded file. In addition to the actions
117
125
  # performed by <tt>data=</tt>, this will set <tt>content_type</tt> and
118
126
  # <tt>filename</tt>.
@@ -104,7 +104,7 @@ module Dis
104
104
  end
105
105
 
106
106
  def stored?
107
- !content_hash.blank?
107
+ @record.dis_stored? && !content_hash.blank?
108
108
  end
109
109
 
110
110
  def stored
@@ -8,7 +8,7 @@ module Dis
8
8
  # Validates that a record has data, either freshly assigned or
9
9
  # persisted in the storage. Adds a `:blank` error on `:data`if not.
10
10
  def validate(record)
11
- record.errors.add(:data, :blank) unless record.data?
11
+ record.errors.add(:data, :blank) if !record.data? || record.data.blank?
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Dis
4
- VERSION = '1.0.5'.freeze
4
+ VERSION = '1.0.6'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails