miasma-local 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ceebf096e1b2813c60f3601a5b54a2ed0e230644
4
- data.tar.gz: 1962f4cdef1ec1017613928760beb706333e24d4
3
+ metadata.gz: 99dd1813acdf0fa0e82689323f18f8a184fa696f
4
+ data.tar.gz: 9406584a5eda5c980d8c1deb6240d099bc8f83b1
5
5
  SHA512:
6
- metadata.gz: 8d0ed1893acc392ab162b25a9e6976e68f50c7b5d9cf767c8bc18385b5b3ba208e5bf7ce97e3cd652dd660e770c5e614d74fbdb62992c68c2f0365023ddba5de
7
- data.tar.gz: abc9904bc3562e61db8400aaeb6336066ff69253887ea45032c1b8c240d7638646ee592e14df8dad61ba7822d562f044ba6d7fdd6a86516cfb52a2d32f9fbded
6
+ metadata.gz: f0a73549aa47d48a4630c82c263a00f2faf6bfea000cfd8e592dbb2adec158fde83495f9b16152a51092a08ec87c6390f4363eb9b23a39bc342200b95949a9cd
7
+ data.tar.gz: e636854511a4a7c00dc72df34c35b76c5ce7ac256fdfc0f80f2787252ebc53f9d5c4b0b2d220f099b5a08591b5e9a3f25c057d56e569bc22db567a0c22bd18cd
@@ -1,2 +1,5 @@
1
+ ## v0.1.2
2
+ * Update implementation to pass specs
3
+
1
4
  ## v0.1.0
2
5
  * Initial release
@@ -1,4 +1,4 @@
1
1
  module MiasmaLocal
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.0')
3
+ VERSION = Gem::Version.new('0.1.2')
4
4
  end
@@ -1,6 +1,7 @@
1
1
  require 'miasma'
2
2
  require 'fileutils'
3
3
  require 'tempfile'
4
+ require 'mime-types'
4
5
 
5
6
  module Miasma
6
7
  module Models
@@ -67,7 +68,7 @@ module Miasma
67
68
  # @return [Array<Models::Storage::Bucket>]
68
69
  def bucket_all
69
70
  Dir.new(object_store_root).map do |item|
70
- if(::File.directory?(item) && !item.start_with?('.'))
71
+ if(::File.directory?(::File.join(object_store_root, item)) && !item.start_with?('.'))
71
72
  Bucket.new(
72
73
  self,
73
74
  :id => ::File.basename(uri_unescape(item)),
@@ -111,8 +112,8 @@ module Miasma
111
112
  bucket,
112
113
  :id => ::File.join(bucket.name, item_name),
113
114
  :name => item_name,
114
- :updated => File.mtime(item),
115
- :size => File.size(item)
115
+ :updated => ::File.mtime(item),
116
+ :size => ::File.size(item)
116
117
  ).valid_state
117
118
  end
118
119
  end.compact
@@ -125,12 +126,16 @@ module Miasma
125
126
  def file_save(file)
126
127
  if(file.dirty?)
127
128
  file.load_data(file.attributes)
128
- if(file.attributes[:body].is_a?(IO))
129
+ if(file.attributes[:body].respond_to?(:readpartial))
129
130
  file.body.rewind
130
131
  tmp_file = Tempfile.new('miasma')
131
- while(content = file.body.read(Storage::READ_BODY_CHUNK_SIZE))
132
- tmp_file.write content
132
+ begin
133
+ while(content = file.body.read(Storage::READ_BODY_CHUNK_SIZE))
134
+ tmp_file.write content
135
+ end
136
+ rescue EOFError
133
137
  end
138
+ tmp_file.flush
134
139
  tmp_file.close
135
140
  FileUtils.mv(tmp_file.path, full_path(file))
136
141
  end
@@ -160,10 +165,13 @@ module Miasma
160
165
  def file_reload(file)
161
166
  if(file.persisted?)
162
167
  new_info = Smash.new.tap do |data|
163
- data[:updated] = File.mtime(full_path(file))
164
- data[:size] = File.size(file_path(file))
165
- data[:etag] = Digest::MD5.hexdigest(content)
166
- data[:content_type] = MIME::Types.of(full_path(file))
168
+ data[:updated] = ::File.mtime(full_path(file))
169
+ data[:size] = ::File.size(full_path(file))
170
+ data[:etag] = Digest::MD5.hexdigest(::File.read(full_path(file))) # @todo Update for block building
171
+ mime = MIME::Types.of(full_path(file)).first
172
+ if(mime)
173
+ data[:content_type] = mime.content_type
174
+ end
167
175
  end
168
176
  file.load_data(file.attributes.deep_merge(new_info))
169
177
  file.valid_state
@@ -178,7 +186,8 @@ module Miasma
178
186
  # @todo where is this in swift?
179
187
  def file_url(file, timeout_secs)
180
188
  if(file.persisted?)
181
- raise NotImplementedError
189
+ "file://#{full_path(file)}"
190
+ full_path(file)
182
191
  else
183
192
  raise Error::ModelPersistError.new "#{file} has not been saved!"
184
193
  end
@@ -191,10 +200,10 @@ module Miasma
191
200
  def file_body(file)
192
201
  if(file.persisted?)
193
202
  tmp_file = Tempfile.new('miasma')
203
+ tmp_path = tmp_file.path
194
204
  tmp_file.delete
195
- FileUtils.cp(full_path(file), tmp_file.path)
196
- tmp_file.open
197
- tmp_file
205
+ FileUtils.cp(full_path(file), tmp_path)
206
+ ::File.open(tmp_path, 'rb')
198
207
  else
199
208
  StringIO.new('')
200
209
  end
@@ -217,12 +226,14 @@ module Miasma
217
226
  # @param file_or_bucket [File, Bucket]
218
227
  # @return [String]
219
228
  def full_path(file_or_bucket)
220
- path = ''
221
- if(file_or_bucket.respond_to?(:bucket))
222
- path << '/' << bucket_path(file_or_bucket.bucket)
229
+ if(file_or_bucket.is_a?(Bucket))
230
+ bucket_path(file_or_bucket)
231
+ else
232
+ ::File.join(
233
+ bucket_path(file_or_bucket.bucket),
234
+ file_path(file_or_bucket)
235
+ )
223
236
  end
224
- path << '/' << file_path(file_or_bucket)
225
- path
226
237
  end
227
238
 
228
239
  # URL string escape
@@ -10,7 +10,12 @@ Gem::Specification.new do |s|
10
10
  s.description = 'Smoggy local API'
11
11
  s.license = 'Apache 2.0'
12
12
  s.require_path = 'lib'
13
- s.add_dependency 'miasma'
14
- s.add_dependency 'mime-types'
13
+ s.add_development_dependency 'miasma', '>= 0.2.12'
14
+ s.add_development_dependency 'pry'
15
+ s.add_development_dependency 'minitest'
16
+ s.add_development_dependency 'vcr'
17
+ s.add_development_dependency 'webmock'
18
+ s.add_development_dependency 'psych', '>= 2.0.8'
19
+ s.add_runtime_dependency 'mime-types'
15
20
  s.files = Dir['lib/**/*'] + %w(miasma-local.gemspec README.md CHANGELOG.md LICENSE)
16
21
  end
metadata CHANGED
@@ -1,29 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miasma-local
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-05 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: miasma
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.12
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.12
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
- type: :runtime
34
+ type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: psych
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.8
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.8
27
97
  - !ruby/object:Gem::Dependency
28
98
  name: mime-types
29
99
  requirement: !ruby/object:Gem::Requirement