dis 1.1.20 → 1.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9ee45bbfd73ef2cb1c66ccfe8acf9690270c8bfaaf772eea29d74562406458e
4
- data.tar.gz: d766ec91185282c91603caf7ac9bd604ca7bfc2ee1a43f9a7e62222e2a6a47da
3
+ metadata.gz: cf00e607df1b1aa62ffa3e025c22ac42e3363d14fb0a06cb6b8f41d3b7757db5
4
+ data.tar.gz: 2cfe7f5a47d87bdd5e6c59e7f98446bec2918a27c8e3476c123ef1164842d437
5
5
  SHA512:
6
- metadata.gz: b613abacbc2b21370cf893d689a5ccda253a3324e60201f15ede8e63c42cb3e2aad258f5c269ff136a097c6d6311dc9afa56f4d204e4dae055abfb8e2897d4fe
7
- data.tar.gz: ee509a0c0403e0e54b631e561e4529793e728958e2a34714dba51ff4bf457ec5b00026b674ce4e01238a8a2f87802ce1bcf4c127fdab3cb0e4f67bf937105ae5
6
+ metadata.gz: e2428a8aa2299b730e1db9702fbec9e725cae6a38bfd3e04bce0ac1ba41484f45840f52cdfe0f998dfe5ffa3c5c5a5fa31bc01c380a1aa8a307392e4a4c9a6a4
7
+ data.tar.gz: d1e9bfbc53cdd753fa0b52730b4c6ac88ec00ca1ba3dd519086fdea58f117947f30d0eb5bef297d952a8fb8deab6d642ce939d5a045d19f70f0586c578b3111e
@@ -16,10 +16,6 @@ module Dis
16
16
 
17
17
  def perform(type, key)
18
18
  Dis::Storage.delayed_store(type, key)
19
- rescue Dis::Errors::NotFoundError
20
- Rails.logger.warn(
21
- "Delayed store failed, object not found: #{[type, key].inspect}"
22
- )
23
19
  end
24
20
  end
25
21
  end
data/lib/dis/layer.rb CHANGED
@@ -136,6 +136,21 @@ module Dis
136
136
  end
137
137
  end
138
138
 
139
+ # Returns the absolute file path for a locally stored file, or nil
140
+ # if the provider is not local or the file does not exist.
141
+ #
142
+ # layer.file_path("documents", key)
143
+ def file_path(type, key)
144
+ return unless connection.respond_to?(:local_root)
145
+ return unless exists?(type, key)
146
+
147
+ File.join(
148
+ connection.local_root,
149
+ directory_component(type, key),
150
+ key_component(type, key)
151
+ )
152
+ end
153
+
139
154
  # Deletes a file from the store.
140
155
  #
141
156
  # layer.delete("documents", key)
@@ -14,9 +14,13 @@ module Dis
14
14
 
15
15
  # Returns true if two Data objects represent the same data.
16
16
  def ==(other)
17
- # TODO: This can be made faster by
18
- # comparing hashes for stored objects.
19
- other.read == read
17
+ if !raw? && other.is_a?(self.class) && !other.changed?
18
+ content_hash == other.content_hash
19
+ elsif other.respond_to?(:read)
20
+ other.read == read
21
+ else
22
+ false
23
+ end
20
24
  end
21
25
 
22
26
  # Returns true if data exists either in memory or in storage.
@@ -66,6 +70,22 @@ module Dis
66
70
  Dis::Storage.store(storage_type, raw)
67
71
  end
68
72
 
73
+ # Clears cached data and tempfiles, allowing them to be garbage
74
+ # collected. Subsequent calls to read or tempfile will re-fetch.
75
+ def reset_read_cache!
76
+ @read = nil
77
+ return unless @tempfile
78
+
79
+ @tempfile.close!
80
+ @tempfile = nil
81
+ end
82
+
83
+ # Returns the file path to the data. Prefers a local storage path
84
+ # to avoid unnecessary copies, falls back to a tempfile.
85
+ def file_path
86
+ local_path || tempfile.path
87
+ end
88
+
69
89
  # Writes the data to a temporary file.
70
90
  def tempfile
71
91
  unless @tempfile
@@ -76,6 +96,12 @@ module Dis
76
96
  @tempfile
77
97
  end
78
98
 
99
+ protected
100
+
101
+ def content_hash
102
+ @record[@record.class.dis_attributes[:content_hash]]
103
+ end
104
+
79
105
  private
80
106
 
81
107
  def closest
@@ -86,10 +112,6 @@ module Dis
86
112
  end
87
113
  end
88
114
 
89
- def content_hash
90
- @record[@record.class.dis_attributes[:content_hash]]
91
- end
92
-
93
115
  def raw?
94
116
  raw ? true : false
95
117
  end
@@ -127,6 +149,12 @@ module Dis
127
149
  Dis::Storage.get(storage_type, content_hash)
128
150
  end
129
151
 
152
+ def local_path
153
+ return if raw?
154
+
155
+ Dis::Storage.file_path(storage_type, content_hash)
156
+ end
157
+
130
158
  attr_reader :raw
131
159
  end
132
160
  end
data/lib/dis/model.rb CHANGED
@@ -131,6 +131,11 @@ module Dis
131
131
  dis_set :filename, file.original_filename
132
132
  end
133
133
 
134
+ # Returns a file path to the data, preferring local storage paths.
135
+ def data_file_path
136
+ dis_data.file_path
137
+ end
138
+
134
139
  # Returns the data as a temporary file.
135
140
  delegate :tempfile, to: :dis_data
136
141
 
data/lib/dis/storage.rb CHANGED
@@ -113,6 +113,19 @@ module Dis
113
113
  result
114
114
  end
115
115
 
116
+ # Returns the absolute file path from the first layer that has a
117
+ # local copy, or nil if no layer stores files locally.
118
+ #
119
+ # Dis::Storage.file_path("things", key)
120
+ def file_path(type, key)
121
+ require_layers!
122
+ layers.each do |layer|
123
+ path = layer.file_path(type, key)
124
+ return path if path
125
+ end
126
+ nil
127
+ end
128
+
116
129
  # Deletes a file from all layers. Kicks off a
117
130
  # <tt>Dis::Jobs::Delete</tt> job if any delayed layers are defined.
118
131
  # Returns true if the file existed in any immediate layers,
data/lib/dis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
- VERSION = "1.1.20"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.20
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
@@ -27,16 +27,22 @@ dependencies:
27
27
  name: fog-core
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.1.2
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: 2.7.0
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
- - - "~>"
40
+ - - ">="
38
41
  - !ruby/object:Gem::Version
39
42
  version: 2.1.2
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: 2.7.0
40
46
  - !ruby/object:Gem::Dependency
41
47
  name: fog-local
42
48
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
134
  - !ruby/object:Gem::Version
129
135
  version: '0'
130
136
  requirements: []
131
- rubygems_version: 3.6.9
137
+ rubygems_version: 4.0.3
132
138
  specification_version: 4
133
139
  summary: A file store for your Rails app
134
140
  test_files: []