dm-parse 0.3.3 → 0.3.4
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.
- data/VERSION +1 -1
- data/dm-parse.gemspec +1 -1
- data/lib/property/parse_file.rb +8 -1
- data/spec/integration_spec.rb +13 -0
- data/spec/parse_file_spec.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.
|
|
1
|
+
0.3.4
|
data/dm-parse.gemspec
CHANGED
data/lib/property/parse_file.rb
CHANGED
|
@@ -4,7 +4,12 @@ module DataMapper
|
|
|
4
4
|
class ParseFile < Object
|
|
5
5
|
|
|
6
6
|
def dump(value)
|
|
7
|
-
|
|
7
|
+
case value
|
|
8
|
+
when ::URI
|
|
9
|
+
{ "__type" => "File", "name" => File.basename(value.path), "url" => value.to_s }
|
|
10
|
+
when ::Hash
|
|
11
|
+
value
|
|
12
|
+
end
|
|
8
13
|
end
|
|
9
14
|
|
|
10
15
|
def load(value)
|
|
@@ -19,6 +24,8 @@ module DataMapper
|
|
|
19
24
|
content_type = value.content_type
|
|
20
25
|
response = adapter.upload_file(filename, content, content_type)
|
|
21
26
|
URI(response["url"])
|
|
27
|
+
elsif value.is_a?(Hash)
|
|
28
|
+
URI(value["url"])
|
|
22
29
|
end
|
|
23
30
|
end
|
|
24
31
|
|
data/spec/integration_spec.rb
CHANGED
|
@@ -35,6 +35,19 @@ describe "resource" do
|
|
|
35
35
|
|
|
36
36
|
it { should eq(content) }
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
context "when resource is persisted" do
|
|
40
|
+
let(:resource) { Article.create attachment: attachment }
|
|
41
|
+
let(:new_attachment) { Struct.new(:original_filename, :read, :content_type).new("x.txt", "yy", "plain/txt") }
|
|
42
|
+
|
|
43
|
+
before { resource.update(attachment: new_attachment) }
|
|
44
|
+
|
|
45
|
+
describe "its file content" do
|
|
46
|
+
subject { Net::HTTP.get resource.attachment }
|
|
47
|
+
|
|
48
|
+
it { should eq("yy") }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
38
51
|
end
|
|
39
52
|
end
|
|
40
53
|
|
data/spec/parse_file_spec.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dm-parse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -241,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
241
241
|
version: '0'
|
|
242
242
|
segments:
|
|
243
243
|
- 0
|
|
244
|
-
hash:
|
|
244
|
+
hash: -4078631318047556530
|
|
245
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
246
|
none: false
|
|
247
247
|
requirements:
|