wire-framework 0.1.5.9 → 0.1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app/cache.rb +26 -7
- data/lib/app/db.rb +7 -7
- data/lib/app/render/document.rb +7 -2
- data/lib/app/render/instant.rb +10 -5
- data/lib/app/render/partial.rb +3 -3
- data/lib/app/repo/svn.rb +33 -24
- data/lib/closet.rb +2 -2
- data/lib/wire.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8029fd3239ff8f787957849338915e540da75f87
|
4
|
+
data.tar.gz: 79cb78ab379a3686efca80e827c5c43834b8a71e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 557fbc73d49212fe4469d81dfa39d29ead0ffe3325f366fbed9fd88f6df66cc2acf4230c17e1056335b1f840399ae6773f004cd4978a77531e9a5311ccbf61c3
|
7
|
+
data.tar.gz: 06c3444d8a889a930122e5472e69836586b706f34f86cdd647961af951e5ce130a6494d57cbf63a097c86ddec723ae345b85b0caf99359381bca4fb383e3e3b0
|
data/lib/app/cache.rb
CHANGED
@@ -17,10 +17,25 @@
|
|
17
17
|
require 'lmdb'
|
18
18
|
|
19
19
|
module Cache
|
20
|
-
|
20
|
+
# Cache::LMDB is a Wire::App for cache arbitrary HTTP responses in an LMDB
|
21
|
+
# @author Bryan T. Meyers
|
22
|
+
module LMDB
|
21
23
|
|
22
24
|
@@cache = {}
|
23
25
|
|
26
|
+
# Cache-specific configuration
|
27
|
+
# @param [Hash] conf the existing configuration
|
28
|
+
# @return [Hash] post-processed configuration
|
29
|
+
def self.configure(conf)
|
30
|
+
unless @@cache[conf['remote']]
|
31
|
+
@@cache[conf['remote']] = LMDB.new("#{conf['cache']}/#{conf['remote']}", mapsize: 2**30)
|
32
|
+
end
|
33
|
+
conf
|
34
|
+
end
|
35
|
+
|
36
|
+
# Add or Update a cached response
|
37
|
+
# @param [Hash] context the context for this request
|
38
|
+
# @return [Response] a valid Rack response triplet, or status code
|
24
39
|
def self.update_cached(context)
|
25
40
|
uri = context.uri.join('/')
|
26
41
|
all = context.uri[0..2].join('/')
|
@@ -53,6 +68,9 @@ module Cache
|
|
53
68
|
result
|
54
69
|
end
|
55
70
|
|
71
|
+
# Read a cached response
|
72
|
+
# @param [Hash] context the context for this request
|
73
|
+
# @return [Response] a valid Rack response triplet, or status code
|
56
74
|
def self.get_cached(context)
|
57
75
|
uri = context.uri.join('/')
|
58
76
|
env = @@cache[context.config['remote']]
|
@@ -64,6 +82,9 @@ module Cache
|
|
64
82
|
result
|
65
83
|
end
|
66
84
|
|
85
|
+
# Remove a cached response
|
86
|
+
# @param [Hash] context the context for this request
|
87
|
+
# @return [Response] a valid Rack response triplet, or status code
|
67
88
|
def self.purge_cached(context)
|
68
89
|
uri = context.uri.join('/')
|
69
90
|
env = @@cache[context.config['remote']]
|
@@ -79,13 +100,11 @@ module Cache
|
|
79
100
|
result
|
80
101
|
end
|
81
102
|
|
103
|
+
# Proxy method used when routing
|
104
|
+
# @param [Array] actions the allowed actions for this URI
|
105
|
+
# @param [Hash] context the context for this request
|
106
|
+
# @return [Response] a Rack Response triplet, or status code
|
82
107
|
def self.invoke(actions, context)
|
83
|
-
|
84
|
-
# Create Cache if not set up
|
85
|
-
unless @@cache[context.config['remote']]
|
86
|
-
@@cache[context.config['remote']] = LMDB.new("/tmp/cache/#{context.config['remote']}", mapsize: 2**30)
|
87
|
-
end
|
88
|
-
|
89
108
|
case context.action
|
90
109
|
when :create, :update, :delete
|
91
110
|
result = context.forward(context.action)
|
data/lib/app/db.rb
CHANGED
@@ -39,11 +39,10 @@ module DB
|
|
39
39
|
conf.each do |k,v|
|
40
40
|
config[k.to_sym] = v
|
41
41
|
end
|
42
|
-
|
43
|
-
config
|
42
|
+
Sequel.connect(config)
|
44
43
|
end
|
45
44
|
|
46
|
-
# Read all of the configs in './
|
45
|
+
# Read all of the configs in './config/dbs'
|
47
46
|
# @return [void]
|
48
47
|
def self.read_configs
|
49
48
|
Wire::Config.read_config_dir('config/dbs', method(:init_db))
|
@@ -132,7 +131,7 @@ module DB
|
|
132
131
|
def self.do_read(context)
|
133
132
|
model = context.config['models'][context.resource]
|
134
133
|
return 404 unless model
|
135
|
-
id = context.
|
134
|
+
id = context.id
|
136
135
|
if id.eql?('new') or id.eql? 'upload'
|
137
136
|
return '{}'
|
138
137
|
end
|
@@ -147,7 +146,7 @@ module DB
|
|
147
146
|
def self.do_update(context)
|
148
147
|
model = context.config['models'][context.resource]
|
149
148
|
return 404 unless model
|
150
|
-
instance = model[context.
|
149
|
+
instance = model[context.id]
|
151
150
|
return 404 unless instance
|
152
151
|
instance.update(context.json)
|
153
152
|
end
|
@@ -158,9 +157,10 @@ module DB
|
|
158
157
|
def self.do_delete(context)
|
159
158
|
model = context.config['models'][context.resource]
|
160
159
|
return 404 unless model
|
161
|
-
instance = model[context.
|
160
|
+
instance = model[context.id]
|
162
161
|
if instance
|
163
|
-
|
162
|
+
instance = instance.destroy
|
163
|
+
if instance.errors.length == 0
|
164
164
|
200
|
165
165
|
else
|
166
166
|
[500, {}, 'Failed to delete instance']
|
data/lib/app/render/document.rb
CHANGED
@@ -27,7 +27,12 @@ module Render
|
|
27
27
|
def self.do_read(actions, context, specific)
|
28
28
|
response = context.forward(specific)
|
29
29
|
mime = response[1]['content-type']
|
30
|
-
renderer =
|
30
|
+
renderer = nil
|
31
|
+
context.closet.renderers.each do |k,c|
|
32
|
+
if c['mimes'].include? mime
|
33
|
+
renderer = c
|
34
|
+
end
|
35
|
+
end
|
31
36
|
if renderer
|
32
37
|
template = renderer['partial']
|
33
38
|
template.render(self, { actions: actions,
|
@@ -58,4 +63,4 @@ module Render
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
end
|
61
|
-
end
|
66
|
+
end
|
data/lib/app/render/instant.rb
CHANGED
@@ -30,7 +30,6 @@ module Render
|
|
30
30
|
if context.resource
|
31
31
|
body = context.body
|
32
32
|
if body
|
33
|
-
#TODO: This looks off...
|
34
33
|
body = body.split('=')[1]
|
35
34
|
if body
|
36
35
|
body = URI.decode(body)
|
@@ -38,12 +37,18 @@ module Render
|
|
38
37
|
## Assume unsupported mime type
|
39
38
|
status = 415
|
40
39
|
message = 'INSTANT: Unsupported MIME Type'
|
41
|
-
|
40
|
+
mime = "#{context.resource}/#{context.id}"
|
41
|
+
renderer = nil
|
42
|
+
context.closet.renderers.each do |k, v|
|
43
|
+
if v['mimes'].include? mime
|
44
|
+
renderer = v['partial']
|
45
|
+
break
|
46
|
+
end
|
47
|
+
end
|
42
48
|
if renderer
|
43
|
-
|
44
|
-
result = template.render(self, { actions: actions,
|
49
|
+
result = renderer.render(self, { actions: actions,
|
45
50
|
context: context,
|
46
|
-
mime:
|
51
|
+
mime: mime,
|
47
52
|
response: body, })
|
48
53
|
name = context.config['template']
|
49
54
|
template = context.closet.templates[name]
|
data/lib/app/render/partial.rb
CHANGED
@@ -58,6 +58,7 @@ module Render
|
|
58
58
|
end
|
59
59
|
if template
|
60
60
|
hash = { actions: actions,
|
61
|
+
context: context,
|
61
62
|
resource: resource,
|
62
63
|
mime: mime,
|
63
64
|
response: body }
|
@@ -103,9 +104,8 @@ module Render
|
|
103
104
|
end
|
104
105
|
if template
|
105
106
|
hash = { actions: actions,
|
106
|
-
|
107
|
-
resource:
|
108
|
-
id: context.id,
|
107
|
+
context: context,
|
108
|
+
resource: resource,
|
109
109
|
mime: mime,
|
110
110
|
response: body }
|
111
111
|
if resource['extras']
|
data/lib/app/repo/svn.rb
CHANGED
@@ -139,43 +139,52 @@ module Repo
|
|
139
139
|
# @param [String] username the Author of this change
|
140
140
|
# @return [Integer] status code
|
141
141
|
def self.do_update_file(conf, repo, id, content, message, mime, username)
|
142
|
-
options
|
143
|
-
status
|
142
|
+
options = "--username #{conf['user']} --password #{conf['password']}"
|
143
|
+
status = 500
|
144
144
|
repo_path = "/tmp/#{username}/#{repo}"
|
145
145
|
unless Dir.exist? repo_path
|
146
146
|
FileUtils.mkdir_p(repo_path)
|
147
147
|
end
|
148
148
|
|
149
|
-
`svn checkout #{options} '#{conf['protocol']}://#{conf['host']}/#{repo}' '#{repo_path}'`
|
149
|
+
`svn checkout --depth empty #{options} '#{conf['protocol']}://#{conf['host']}/#{repo}' '#{repo_path}'`
|
150
150
|
|
151
151
|
if $?.exitstatus == 0
|
152
|
-
|
153
|
-
|
154
|
-
|
152
|
+
Dir.chdir(repo_path) do
|
153
|
+
file_path = CGI.unescape(id)
|
154
|
+
if conf['web_folder']
|
155
|
+
file_path = "#{conf['web_folder']}/#{file_path}"
|
156
|
+
end
|
157
|
+
folder_path = file_path.split('/')
|
158
|
+
folder_path.pop
|
159
|
+
folder_path = folder_path.join('/')
|
160
|
+
`svn update --parents #{options} #{file_path}`
|
161
|
+
unless Dir.exist? folder_path
|
162
|
+
FileUtils.mkdir_p(folder_path)
|
163
|
+
end
|
164
|
+
file = File.open(file_path, 'w')
|
165
|
+
file.syswrite(content)
|
166
|
+
file.close
|
167
|
+
`svn add --force *`
|
168
|
+
$stderr.puts `svn status`
|
169
|
+
`svn propset svn:mime-type '#{mime ? mime : 'application/octet-stream'}' #{file_path}`
|
170
|
+
if $?.exitstatus != 0
|
171
|
+
break
|
172
|
+
end
|
173
|
+
`svn commit #{options} -m "#{message}"`
|
174
|
+
if $?.exitstatus != 0
|
175
|
+
break
|
176
|
+
end
|
177
|
+
`svn propset #{options} --revprop -r HEAD svn:author '#{username}'`
|
155
178
|
end
|
156
|
-
folder_path = file_path.split('/')
|
157
|
-
folder_path.pop
|
158
|
-
folder_path = folder_path.join('/')
|
159
|
-
|
160
|
-
unless Dir.exist? folder_path
|
161
|
-
FileUtils.mkdir_p(folder_path)
|
162
|
-
end
|
163
|
-
|
164
|
-
file = File.open(file_path, 'w+')
|
165
|
-
file.syswrite(content)
|
166
|
-
file.close
|
167
|
-
`svn add --force "#{repo_path}/*"`
|
168
|
-
`svn propset svn:mime-type "#{mime}" "#{file_path}"`
|
169
|
-
`svn commit #{options} -m "#{message}" "#{repo_path}"`
|
170
|
-
if $?.exitstatus == 0
|
171
|
-
status = 200
|
172
|
-
end
|
173
|
-
`svn propset #{options} --revprop -r HEAD svn:author '#{username}' "#{repo_path}"`
|
174
179
|
end
|
175
180
|
`rm -R '#{repo_path}'`
|
181
|
+
if $?.exitstatus == 0
|
182
|
+
status = 200
|
183
|
+
end
|
176
184
|
status
|
177
185
|
end
|
178
186
|
|
187
|
+
|
179
188
|
# Create a single file
|
180
189
|
# @param [String] conf the repo config
|
181
190
|
# @param [String] repo the new repo name
|
data/lib/closet.rb
CHANGED
@@ -43,11 +43,11 @@ module Wire
|
|
43
43
|
if @mode.eql? 'development'
|
44
44
|
$stderr.puts 'Reading DB Configs...'
|
45
45
|
end
|
46
|
-
@dbs =
|
46
|
+
@dbs = DB.read_configs
|
47
47
|
if @mode.eql? 'development'
|
48
48
|
$stderr.puts 'Reading Repo Configs...'
|
49
49
|
end
|
50
|
-
@repos =
|
50
|
+
@repos = Repo.read_configs
|
51
51
|
end
|
52
52
|
|
53
53
|
# Setup the closet
|
data/lib/wire.rb
CHANGED