social_snippet-supports-mongoid 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/social_snippet/storage_backend/mongoid_storage.rb +133 -0
- data/lib/social_snippet/storage_backend/mongoid_storage/file.rb +13 -0
- data/lib/social_snippet/storage_backend/mongoid_storage/model.rb +12 -0
- data/lib/social_snippet/supports/mongoid.rb +3 -0
- data/lib/social_snippet/supports/mongoid/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2EyYjgzYjgzYTVmZjFlOWJlNmFmNzVlNmNlYjQyMWFmNjI3MDk1NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWUwZmU3OWYyZWNjMmYxMWU2M2M0N2NiZTNhNGQ3MDFjOTdlZGY4YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGRmOTMwMzI2NmJlMzg5OTU3ZTg3ZDYyY2FiZDM2ODIwMWExNTE0OGQ0Y2Fh
|
10
|
+
NTg3YmRkMmJmN2RlMDdiNGI3Nzc1YzU2YjVmZGIxYmNkYTc4Yzg1NjgzOGMz
|
11
|
+
NTY5ZmZkYjg0MmVhYjQ0MjVhMmQxNTdmM2Y2NTk3MGU2ZDJiYjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmY4YmZmMmFlYWJlZDNiNDhkYjlkZmJlZDk5N2NjMmExZjlhZGEyMzgxOWY1
|
14
|
+
ZDc5YWE3ZjA5MGNkMDIwODE0MDhjMTZjZDdiZDFmMTViZjcwMWZiNDM1NTdm
|
15
|
+
ZDRkYmRkNWVhNmU3NmU1OWJiYTE3ZjdkZjMyOTIyMmFkYWNlNjQ=
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module SocialSnippet::StorageBackend
|
2
|
+
|
3
|
+
class MongoidStorage
|
4
|
+
|
5
|
+
require_relative "mongoid_storage/file"
|
6
|
+
require_relative "mongoid_storage/model"
|
7
|
+
|
8
|
+
attr_reader :paths
|
9
|
+
attr_reader :workdir
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@workdir = "/"
|
13
|
+
@paths = ::SortedSet.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def cd(path)
|
17
|
+
if absolute?(path)
|
18
|
+
@workdir = normalize(path)
|
19
|
+
else
|
20
|
+
@workdir = resolve(path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def touch(path)
|
25
|
+
realpath = resolve(path)
|
26
|
+
paths.add realpath
|
27
|
+
end
|
28
|
+
|
29
|
+
def write(path, content)
|
30
|
+
realpath = resolve(path)
|
31
|
+
raise ::Errno::EISDIR if directory?(path)
|
32
|
+
paths.add realpath
|
33
|
+
file = File.find_or_create_by(:path => realpath)
|
34
|
+
file.update_attributes(
|
35
|
+
:content => content,
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def read(path)
|
40
|
+
realpath = resolve(path)
|
41
|
+
raise ::Errno::EISDIR if directory?(path)
|
42
|
+
file = File.find_by(
|
43
|
+
:path => realpath,
|
44
|
+
)
|
45
|
+
file.content
|
46
|
+
end
|
47
|
+
|
48
|
+
def mkdir(path)
|
49
|
+
realpath = resolve(path)
|
50
|
+
raise ::Errno::EEXIST if exists?(realpath)
|
51
|
+
mkdir_p path
|
52
|
+
end
|
53
|
+
|
54
|
+
def mkdir_p(path)
|
55
|
+
realpath = resolve(path)
|
56
|
+
raise ::Errno::EEXIST if file?(realpath)
|
57
|
+
paths.add realpath
|
58
|
+
paths.add dirpath(realpath)
|
59
|
+
end
|
60
|
+
|
61
|
+
def exists?(path)
|
62
|
+
realpath = resolve(path)
|
63
|
+
paths.include?(realpath) ||
|
64
|
+
paths.include?(dirpath realpath)
|
65
|
+
end
|
66
|
+
|
67
|
+
def rm(path)
|
68
|
+
realpath = resolve(path)
|
69
|
+
paths.delete realpath
|
70
|
+
end
|
71
|
+
|
72
|
+
def rm_r(path)
|
73
|
+
realpath = resolve(path)
|
74
|
+
paths.reject! do |tmp_path|
|
75
|
+
tmp_path.start_with? realpath
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def directory?(path)
|
80
|
+
realpath = resolve(path)
|
81
|
+
paths.include? dirpath(realpath)
|
82
|
+
end
|
83
|
+
|
84
|
+
def file?(path)
|
85
|
+
return false if directory?(path)
|
86
|
+
realpath = resolve(path)
|
87
|
+
paths.include? realpath
|
88
|
+
end
|
89
|
+
|
90
|
+
def glob(pattern)
|
91
|
+
realpattern = resolve(pattern)
|
92
|
+
paths.select do |path|
|
93
|
+
::File.fnmatch realpattern, path, ::File::FNM_PATHNAME
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def pwd
|
98
|
+
workdir
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.activate!
|
102
|
+
::SocialSnippet.class_eval do
|
103
|
+
remove_const :Storage if defined?(::SocialSnippet::Storage)
|
104
|
+
const_set :Storage, ::SocialSnippet::StorageBackend::MongoidStorage
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def absolute?(path)
|
111
|
+
::Pathname.new(path).absolute?
|
112
|
+
end
|
113
|
+
|
114
|
+
def resolve(path)
|
115
|
+
if absolute?(path)
|
116
|
+
normalize(path)
|
117
|
+
else
|
118
|
+
normalize(::File.join workdir, path)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def dirpath(path)
|
123
|
+
path + "/"
|
124
|
+
end
|
125
|
+
|
126
|
+
def normalize(path)
|
127
|
+
::Pathname.new(path).cleanpath.to_s
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require "mongoid"
|
2
|
+
require "pathname"
|
2
3
|
require "social_snippet/supports/mongoid/version"
|
3
4
|
require "social_snippet/document_backend/mongoid_document"
|
5
|
+
require "social_snippet/storage_backend/mongoid_storage"
|
4
6
|
|
5
7
|
module SocialSnippet::Supports
|
6
8
|
|
@@ -8,6 +10,7 @@ module SocialSnippet::Supports
|
|
8
10
|
|
9
11
|
def self.activate!
|
10
12
|
::SocialSnippet::DocumentBackend::MongoidDocument.activate!
|
13
|
+
::SocialSnippet::StorageBackend::MongoidStorage.activate!
|
11
14
|
end
|
12
15
|
|
13
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_snippet-supports-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki Sano
|
@@ -164,6 +164,9 @@ files:
|
|
164
164
|
- Rakefile
|
165
165
|
- config/database.rb
|
166
166
|
- lib/social_snippet/document_backend/mongoid_document.rb
|
167
|
+
- lib/social_snippet/storage_backend/mongoid_storage.rb
|
168
|
+
- lib/social_snippet/storage_backend/mongoid_storage/file.rb
|
169
|
+
- lib/social_snippet/storage_backend/mongoid_storage/model.rb
|
167
170
|
- lib/social_snippet/supports/mongoid.rb
|
168
171
|
- lib/social_snippet/supports/mongoid/version.rb
|
169
172
|
- social_snippet-supports-mongoid.gemspec
|