file_model 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -3
- data/lib/file_model/adapter.rb +1 -1
- data/lib/file_model/file_model.rb +6 -6
- data/lib/file_model/helper.rb +1 -1
- data/lib/file_model/spec.rb +2 -2
- data/lib/file_model/spec/shared_crud.rb +2 -2
- data/spec/abstract_model_spec.rb +1 -1
- data/spec/adapter_spec.rb +1 -1
- data/spec/file_model_spec.rb +2 -2
- data/spec/spec_helper/model_stub.rb +4 -4
- metadata +8 -8
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'rake_ext'
|
2
2
|
|
3
|
-
project
|
3
|
+
project \
|
4
4
|
name: "file_model",
|
5
5
|
gem: true,
|
6
6
|
summary: "File storage for Models",
|
7
7
|
|
8
8
|
author: "Alexey Petrushin",
|
9
|
-
homepage: "http://github.com/alexeypetrushin/file_model"
|
10
|
-
)
|
9
|
+
homepage: "http://github.com/alexeypetrushin/file_model"
|
data/lib/file_model/adapter.rb
CHANGED
@@ -39,7 +39,7 @@ class FileModel::Adapter
|
|
39
39
|
if dir.exist?
|
40
40
|
dir.to_dir.entries do |entry|
|
41
41
|
entry_time = entry.name.to_i
|
42
|
-
entry.
|
42
|
+
entry.delete if (entry_time > time) or (time > (entry_time + EXPIRATION_TIME))
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -20,7 +20,7 @@ module FileModel
|
|
20
20
|
return false unless options[:validate] == false or valid?
|
21
21
|
|
22
22
|
# deleting old files
|
23
|
-
|
23
|
+
delete validate: false
|
24
24
|
|
25
25
|
# saving
|
26
26
|
self.name = build_name original.name
|
@@ -45,24 +45,24 @@ module FileModel
|
|
45
45
|
save(options) || raise("can't save #{self} (#{errors.inspect})!")
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def delete options = {}
|
49
49
|
return true unless name
|
50
50
|
|
51
51
|
return false unless options[:validate] == false or valid?
|
52
52
|
|
53
53
|
path = build_path name
|
54
|
-
self.class.box[path].
|
54
|
+
self.class.box[path].delete
|
55
55
|
|
56
56
|
self.class.versions.each do |version_name, klass|
|
57
57
|
path = build_path name, version_name
|
58
|
-
self.class.box[path].
|
58
|
+
self.class.box[path].delete
|
59
59
|
end
|
60
60
|
|
61
61
|
true
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
65
|
-
|
64
|
+
def delete! options = {}
|
65
|
+
delete(options) || raise("can't delete #{self} (#{errors.inspect})!")
|
66
66
|
end
|
67
67
|
|
68
68
|
def url
|
data/lib/file_model/helper.rb
CHANGED
data/lib/file_model/spec.rb
CHANGED
@@ -19,11 +19,11 @@ rspec do
|
|
19
19
|
tmp = '/tmp/file_model_test'.to_dir
|
20
20
|
|
21
21
|
before do
|
22
|
-
tmp.
|
22
|
+
tmp.delete.create
|
23
23
|
FileModel.box = Vos::Box.new(Vos::Drivers::Local.new(root: tmp.path))
|
24
24
|
end
|
25
25
|
|
26
|
-
after{tmp.
|
26
|
+
after{tmp.delete}
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -73,8 +73,8 @@ shared_examples_for 'file model crud' do
|
|
73
73
|
file_model_storage['storage/images/sea/ship.jpg'].exist?.should be_false
|
74
74
|
file_model_storage['storage/images/sea/ship2.jpg'].exist?.should be_true
|
75
75
|
|
76
|
-
#
|
77
|
-
model.
|
76
|
+
# deleteing
|
77
|
+
model.delete.should be_true
|
78
78
|
file_model_storage['storage/images/sea/ship2.jpg'].exist?.should be_false
|
79
79
|
end
|
80
80
|
|
data/spec/abstract_model_spec.rb
CHANGED
data/spec/adapter_spec.rb
CHANGED
data/spec/file_model_spec.rb
CHANGED
@@ -117,10 +117,10 @@ describe "File Model" do
|
|
117
117
|
image.icon.file.exist?.should be_true
|
118
118
|
image.icon.url.should == '/images/ship2.icon.jpg'
|
119
119
|
|
120
|
-
#
|
120
|
+
# deleteing
|
121
121
|
image = ImageFile.new
|
122
122
|
image.read 'ship2.jpg'
|
123
|
-
image.
|
123
|
+
image.delete
|
124
124
|
file_model_storage['storage/images/ship2.jpg'].exist?.should be_false
|
125
125
|
file_model_storage['storage/images/ship2.icon.jpg'].exist?.should be_false
|
126
126
|
end
|
@@ -15,12 +15,12 @@ class ModelStub
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def delete
|
19
19
|
self.class.before_validate.each{|block| instance_eval &block}
|
20
20
|
|
21
21
|
if errors.empty?
|
22
22
|
# save
|
23
|
-
self.class.
|
23
|
+
self.class.after_delete.each{|block| instance_eval &block}
|
24
24
|
true
|
25
25
|
else
|
26
26
|
false
|
@@ -36,8 +36,8 @@ class ModelStub
|
|
36
36
|
@after_save ||= []
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
@
|
39
|
+
def after_delete
|
40
|
+
@after_delete ||= []
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby_ext
|
16
|
-
requirement: &
|
16
|
+
requirement: &2849270 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2849270
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: vfs
|
27
|
-
requirement: &
|
27
|
+
requirement: &2849030 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2849030
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: vos
|
38
|
-
requirement: &
|
38
|
+
requirement: &2848790 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2848790
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
executables: []
|