uzuuzu-core 0.0.9 → 0.0.10
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/lib/uzuuzu/application.rb +20 -49
- data/lib/uzuuzu/controller.rb +1 -0
- data/lib/uzuuzu/controller/error.rb +1 -1
- data/lib/uzuuzu/datastore/datamapper.rb +106 -0
- data/lib/uzuuzu/helper.rb +0 -1
- data/lib/uzuuzu/helper/controller.rb +53 -14
- data/lib/uzuuzu/helper/renderer.rb +2 -99
- data/lib/uzuuzu/lang/en.yaml +0 -9
- data/lib/uzuuzu/lang/ja.yaml +1 -0
- data/lib/uzuuzu/model.rb +49 -0
- data/lib/uzuuzu/response.rb +116 -0
- data/lib/uzuuzu/service.rb +48 -0
- data/lib/uzuuzu/wrapper/uzuuzu.rb +24 -0
- data/lib/uzuuzu_core.rb +3 -1
- data/uzuuzu-core.gemspec +4 -4
- metadata +5 -5
- data/lib/uzuuzu/fixture/datamapper.rb +0 -114
- data/lib/uzuuzu/helper/uzuuzu.rb +0 -48
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/lib/uzuuzu/application.rb
CHANGED
@@ -18,8 +18,6 @@ module UzuUzu
|
|
18
18
|
#
|
19
19
|
attr_accessor :after_filters
|
20
20
|
#
|
21
|
-
attr_accessor :dicons
|
22
|
-
#
|
23
21
|
attr_accessor :helpers
|
24
22
|
#
|
25
23
|
attr_accessor :views
|
@@ -73,24 +71,9 @@ module UzuUzu
|
|
73
71
|
def after_filters
|
74
72
|
@after_filters ||= self.class.after_filters.clone
|
75
73
|
end
|
76
|
-
|
77
|
-
def self.dicons
|
78
|
-
@@dicons ||= [
|
79
|
-
Helper::UzuUzuHelper,
|
80
|
-
Helper::Controller,
|
81
|
-
Helper::Renderer,
|
82
|
-
Helper::Localize,
|
83
|
-
Helper::Route,
|
84
|
-
]
|
85
|
-
end
|
86
|
-
|
87
|
-
def dicons
|
88
|
-
@dicons ||= self.class.dicons.clone
|
89
|
-
end
|
90
74
|
|
91
75
|
def self.helpers
|
92
76
|
@@helpers ||= [
|
93
|
-
Helper::UzuUzuHelper,
|
94
77
|
Helper::Controller,
|
95
78
|
Helper::Form,
|
96
79
|
Helper::Jquery,
|
@@ -122,7 +105,8 @@ module UzuUzu
|
|
122
105
|
response = UzuUzu::Response.new
|
123
106
|
clazz = find_controller(env)
|
124
107
|
if clazz.blank?
|
125
|
-
|
108
|
+
di_thread(request, response, nil, nil, nil, nil, nil)
|
109
|
+
return not_found(response)
|
126
110
|
end
|
127
111
|
|
128
112
|
is_send = false
|
@@ -133,23 +117,22 @@ module UzuUzu
|
|
133
117
|
query = map[:query]
|
134
118
|
route = map[:route]
|
135
119
|
controller = controller_class.new
|
136
|
-
include_dicon(controller)
|
137
120
|
helper = Helper::Helper.new
|
138
121
|
include_helper(helper)
|
139
122
|
|
140
123
|
action, query = find_action(controller, query)
|
124
|
+
di_thread(request, response, controller, helper, action, query, route)
|
141
125
|
next if action.blank?
|
142
126
|
is_send = true
|
143
|
-
di_thread(request, response, controller, helper, action, query, route)
|
144
127
|
action_return = send_action(request, response, controller, action, query)
|
145
128
|
if response.body.blank?
|
146
|
-
render =
|
129
|
+
render = helper.render(action)
|
147
130
|
end
|
148
131
|
break
|
149
132
|
end
|
150
133
|
|
151
134
|
unless is_send
|
152
|
-
return not_found(
|
135
|
+
return not_found(response)
|
153
136
|
end
|
154
137
|
if response.status == 200 and response.body.blank?
|
155
138
|
response.write render || action_return
|
@@ -216,18 +199,15 @@ module UzuUzu
|
|
216
199
|
#
|
217
200
|
#
|
218
201
|
#
|
219
|
-
def include_dicon(controller)
|
220
|
-
dicons.each do |dicon|
|
221
|
-
controller.extend(dicon)
|
222
|
-
end
|
223
|
-
end # include_dicon
|
224
|
-
|
225
202
|
def include_helper(helper)
|
226
203
|
helpers.each do |h|
|
227
204
|
helper.extend(h)
|
228
205
|
end
|
229
206
|
end # include_helper
|
230
207
|
|
208
|
+
#
|
209
|
+
#
|
210
|
+
#
|
231
211
|
def di_thread(request, response, controller, helper, action, query, route)
|
232
212
|
current = ::Thread.current
|
233
213
|
current[:request] = request
|
@@ -266,22 +246,22 @@ module UzuUzu
|
|
266
246
|
end
|
267
247
|
end
|
268
248
|
end
|
269
|
-
unless (arity >= 0 && query.size == arity)
|
249
|
+
unless (arity >= 0 && query.size == arity) ||
|
270
250
|
(arity < 0 && query.size >= ((-1 * arity)-1))
|
271
251
|
index_flag = true
|
272
252
|
end
|
273
253
|
if index_flag && !(action == 'index') && controller.respond_to?(:index)
|
274
254
|
query.unshift(action)
|
275
255
|
action = 'index'
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
282
|
-
else
|
256
|
+
end
|
257
|
+
if controller.respond_to?(action)
|
258
|
+
arity = controller.method(action).arity
|
259
|
+
unless (arity >= 0 && query.size == arity) ||
|
260
|
+
(arity < 0 && query.size >= ((-1 * arity)-1))
|
283
261
|
action = nil
|
284
262
|
end
|
263
|
+
else
|
264
|
+
action = nil
|
285
265
|
end
|
286
266
|
end
|
287
267
|
[action, query]
|
@@ -313,21 +293,12 @@ module UzuUzu
|
|
313
293
|
end
|
314
294
|
value
|
315
295
|
end # send_action
|
316
|
-
|
317
|
-
def
|
318
|
-
|
319
|
-
|
320
|
-
if (request.scheme == 'https' and request.port != 443) or
|
321
|
-
(request.scheme == 'http' and request.port != 80)
|
322
|
-
uri << ":#{request.port}"
|
296
|
+
|
297
|
+
def not_found(response)
|
298
|
+
catch(:finish) do
|
299
|
+
response.redirect("/error/404")
|
323
300
|
end
|
324
|
-
uri << "#{request.env["SCRIPT_NAME"]}/error/#{code}"
|
325
|
-
response.redirect(uri)
|
326
301
|
response.finish
|
327
302
|
end
|
328
|
-
|
329
|
-
def not_found(request, response)
|
330
|
-
error(404, request, response)
|
331
|
-
end
|
332
303
|
end # Application
|
333
304
|
end # UzuUzu
|
data/lib/uzuuzu/controller.rb
CHANGED
@@ -110,7 +110,113 @@ module UzuUzu
|
|
110
110
|
end
|
111
111
|
false
|
112
112
|
end
|
113
|
+
|
114
|
+
def import_file(model, file, overwrite=false)
|
115
|
+
unless ::File.file?(file)
|
116
|
+
raise "UzuUzu fixture import error file not found : #{file}"
|
117
|
+
end
|
118
|
+
ext = ::File.extname(file)
|
119
|
+
case(ext)
|
120
|
+
when '.yml', '.yaml'
|
121
|
+
import_yaml(model, ::YAML.load_file(file), overwrite)
|
122
|
+
when '.xml'
|
123
|
+
# TODO
|
124
|
+
when '.json', '.js'
|
125
|
+
# TODO
|
126
|
+
when '.csv'
|
127
|
+
begin
|
128
|
+
require 'fastercsv'
|
129
|
+
::FasterCSV.foreach(file) do |row|
|
130
|
+
import_csv(model, row, overwrite)
|
131
|
+
end
|
132
|
+
rescue
|
133
|
+
require "csv"
|
134
|
+
::CSV.open(file) do |row|
|
135
|
+
import_csv(model, row, overwrite)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
nil
|
140
|
+
end
|
141
|
+
|
142
|
+
def import_yaml(model, yaml, overwrite=false)
|
143
|
+
::UzuUzu.logger.debug 'import yaml'
|
144
|
+
transaction do |tr|
|
145
|
+
tr.begin
|
146
|
+
begin
|
147
|
+
if yaml.kind_of?(Array)
|
148
|
+
yaml.each do |map|
|
149
|
+
::UzuUzu.logger.debug "import #{map.inspect}"
|
150
|
+
resource = model.first(:id => map[:id]) unless map[:id].nil?
|
151
|
+
if resource.nil?
|
152
|
+
resource = model.new(map)
|
153
|
+
unless resource.valid?
|
154
|
+
::UzuUzu.logger.error resource.errors
|
155
|
+
end
|
156
|
+
resource.save
|
157
|
+
elsif overwrite
|
158
|
+
resource.update(map)
|
159
|
+
unless resource.valid?
|
160
|
+
::UzuUzu.logger.error resource.errors
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
elsif yaml.kind_of?(Hash)
|
165
|
+
::UzuUzu.logger.debug "import #{yaml.inspect}"
|
166
|
+
resource = model.first(:id => yaml[:id]) unless yaml[:id].nil?
|
167
|
+
if resource.nil?
|
168
|
+
resource = model.new(yaml)
|
169
|
+
unless resource.valid?
|
170
|
+
::UzuUzu.logger.error resource.errors
|
171
|
+
end
|
172
|
+
resource.save
|
173
|
+
elsif overwrite
|
174
|
+
resource.update(yaml)
|
175
|
+
unless resource.valid?
|
176
|
+
::UzuUzu.logger.error resource.errors
|
177
|
+
end
|
178
|
+
end
|
179
|
+
else
|
180
|
+
::UzuUzu.logger.error "import type miss match #{yaml.inspect}"
|
181
|
+
end
|
182
|
+
::UzuUzu.logger.debug 'imported yaml'
|
183
|
+
tr.commit
|
184
|
+
rescue => e
|
185
|
+
tr.rollback
|
186
|
+
raise e
|
187
|
+
end
|
188
|
+
end # transaction
|
189
|
+
end # import_yaml
|
190
|
+
|
191
|
+
def import_json(model, json, overwrite=false)
|
192
|
+
# TODO
|
193
|
+
end
|
194
|
+
|
195
|
+
def import_xml(model, xml, overwrite=false)
|
196
|
+
# TODO
|
197
|
+
end
|
113
198
|
|
199
|
+
def import_csv(model, csv, overwrite=false)
|
200
|
+
transaction do |tr|
|
201
|
+
tr.begin
|
202
|
+
begin
|
203
|
+
resource = model.first(:id => csv[0])
|
204
|
+
csv.each_with_index do |culumn, index|
|
205
|
+
if resource.nil? || overwrite
|
206
|
+
resource ||= model.new
|
207
|
+
resource.properties.each_with_index do |property, column_no|
|
208
|
+
resource[property.name] = culumn if index = column_no
|
209
|
+
end
|
210
|
+
resource.save
|
211
|
+
end
|
212
|
+
end
|
213
|
+
tr.commit
|
214
|
+
rescue => e
|
215
|
+
tr.rollback
|
216
|
+
raise e
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end # import_csv
|
114
220
|
end # Datamapper
|
115
221
|
end # DataStore
|
116
222
|
end # UzuUzu
|
data/lib/uzuuzu/helper.rb
CHANGED
@@ -8,7 +8,6 @@ module UzuUzu
|
|
8
8
|
autoload(:Localize, 'uzuuzu/helper/localize')
|
9
9
|
autoload(:Renderer, 'uzuuzu/helper/renderer')
|
10
10
|
autoload(:Route, 'uzuuzu/helper/route')
|
11
|
-
autoload(:UzuUzuHelper, 'uzuuzu/helper/uzuuzu')
|
12
11
|
autoload(:XHtml, 'uzuuzu/helper/xhtml')
|
13
12
|
|
14
13
|
def self.current
|
@@ -9,6 +9,41 @@ module UzuUzu
|
|
9
9
|
#
|
10
10
|
#
|
11
11
|
module Controller
|
12
|
+
#
|
13
|
+
#
|
14
|
+
#
|
15
|
+
def logger
|
16
|
+
::UzuUzu.logger
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
#
|
21
|
+
#
|
22
|
+
def memcache
|
23
|
+
::UzuUzu.memcache
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
#
|
28
|
+
#
|
29
|
+
def kvs
|
30
|
+
::UzuUzu.kvs
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
#
|
35
|
+
#
|
36
|
+
def datastore
|
37
|
+
::UzuUzu.datastore
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
#
|
42
|
+
#
|
43
|
+
def mailer
|
44
|
+
::UzuUzu.mailer
|
45
|
+
end
|
46
|
+
|
12
47
|
#
|
13
48
|
#
|
14
49
|
#
|
@@ -20,28 +55,42 @@ module UzuUzu
|
|
20
55
|
#
|
21
56
|
#
|
22
57
|
def controller
|
23
|
-
::UzuUzu
|
58
|
+
::UzuUzu.controller
|
24
59
|
end
|
25
60
|
|
26
61
|
#
|
27
62
|
#
|
28
63
|
#
|
29
64
|
def request
|
30
|
-
::UzuUzu
|
65
|
+
::UzuUzu.request
|
31
66
|
end
|
32
67
|
|
33
68
|
#
|
34
69
|
#
|
35
70
|
#
|
36
71
|
def response
|
37
|
-
::UzuUzu
|
72
|
+
::UzuUzu.response
|
38
73
|
end
|
39
74
|
|
40
75
|
#
|
41
76
|
#
|
42
77
|
#
|
43
78
|
def helper
|
44
|
-
::UzuUzu
|
79
|
+
::UzuUzu.helper
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
#
|
84
|
+
#
|
85
|
+
def model
|
86
|
+
::UzuUzu.model
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
#
|
91
|
+
#
|
92
|
+
def service
|
93
|
+
::UzuUzu.service
|
45
94
|
end
|
46
95
|
|
47
96
|
#
|
@@ -86,16 +135,6 @@ module UzuUzu
|
|
86
135
|
Rack::Utils.unescape(s)
|
87
136
|
end
|
88
137
|
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
def mime_type(type, value=nil)
|
93
|
-
return type if type.nil? || type.to_s.include?('/')
|
94
|
-
type = ".#{type}" unless type.to_s[0] == ?.
|
95
|
-
return Rack::Mime.mime_type(type, nil) if value.nil?
|
96
|
-
Rack::Mime::MIME_TYPES[type] = value
|
97
|
-
end
|
98
|
-
|
99
138
|
#
|
100
139
|
#
|
101
140
|
#
|
@@ -16,32 +16,12 @@ module UzuUzu
|
|
16
16
|
_query = query
|
17
17
|
_route = route
|
18
18
|
browser = ::Rack::MockRequest.new(::UzuUzu.current)
|
19
|
-
_render_response = browser.get(
|
19
|
+
_render_response = browser.get(helper.rf(controller_clazz, action, options))
|
20
20
|
_render = _render_response.body.to_s
|
21
21
|
::UzuUzu.current.di_thread(_request, _response, _controller, _helper, _action, _query, _route)
|
22
22
|
_render
|
23
23
|
end
|
24
24
|
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
def respond(string, mime=nil, status=200)
|
29
|
-
response.status = 200
|
30
|
-
response["Content-Type"] = mime_type(mime) || mime unless mime.nil?
|
31
|
-
response.write string
|
32
|
-
throw :finish
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
def respond_to
|
39
|
-
return unless block_given?
|
40
|
-
response.status = 200
|
41
|
-
contents = yield(request.wish)
|
42
|
-
respond(contents, request.wish) if contents and response.successful?
|
43
|
-
end
|
44
|
-
|
45
25
|
#
|
46
26
|
#
|
47
27
|
#
|
@@ -50,7 +30,7 @@ module UzuUzu
|
|
50
30
|
catch(:view_finded) do
|
51
31
|
::Tilt.mappings.each_key do |key|
|
52
32
|
application.views.each do |view_route|
|
53
|
-
_view_path = "#{view_route}#{
|
33
|
+
_view_path = "#{view_route}#{helper.route}/#{view}.#{key}"
|
54
34
|
if ::File.file?(_view_path)
|
55
35
|
view_path = _view_path
|
56
36
|
throw :view_finded
|
@@ -85,83 +65,6 @@ module UzuUzu
|
|
85
65
|
UzuUzu.render_engine(helper, view_string, engine, options, locals, &block)
|
86
66
|
end
|
87
67
|
|
88
|
-
def send_file()
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
def send_binary()
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
def redirect(uri, options={})
|
100
|
-
if not uri =~ /^https?:\/\//
|
101
|
-
abs_uri = "#{request.scheme}://#{request.host}"
|
102
|
-
|
103
|
-
if request.scheme == 'https' && request.port != 443 ||
|
104
|
-
request.scheme == 'http' && request.port != 80
|
105
|
-
abs_uri << ":#{request.port}"
|
106
|
-
end
|
107
|
-
uri = (abs_uri << uri)
|
108
|
-
end
|
109
|
-
uri << query_string(options)
|
110
|
-
response.redirect(uri)
|
111
|
-
throw :finish
|
112
|
-
end # redirect
|
113
|
-
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
def server_error(code=500, options={})
|
118
|
-
redirect controller.rf(UzuUzu::Controller::Index, :error, code)
|
119
|
-
end # error
|
120
|
-
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
def not_found(code=404, options={})
|
125
|
-
redirect controller.rf(UzuUzu::Controller::Index, :error, code)
|
126
|
-
end
|
127
|
-
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
def last_modified(time)
|
132
|
-
return unless time
|
133
|
-
if time.respond_to?(:to_time)
|
134
|
-
time = time.to_time
|
135
|
-
else
|
136
|
-
time = ::Time.parse(time.to_s)
|
137
|
-
end
|
138
|
-
response['Last-Modified'] = time.httpdate
|
139
|
-
if ::Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
|
140
|
-
response.status = 304
|
141
|
-
throw :finish
|
142
|
-
end
|
143
|
-
end # last_modified
|
144
|
-
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
def etag(value, kind=:strong)
|
149
|
-
raise ::TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
|
150
|
-
value = '"%s"' % value
|
151
|
-
value = 'W/' + value if kind == :weak
|
152
|
-
response['ETag'] = value
|
153
|
-
|
154
|
-
# Conditional GET check
|
155
|
-
if etags = env['HTTP_IF_NONE_MATCH']
|
156
|
-
etags = etags.split(/\s*,\s*/)
|
157
|
-
if etags.include?(value) || etags.include?('*')
|
158
|
-
response.status = 304
|
159
|
-
throw :finish
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end # etag
|
163
|
-
|
164
|
-
|
165
68
|
end # Renderer
|
166
69
|
end # Helper
|
167
70
|
end # UzuUzu
|
data/lib/uzuuzu/lang/en.yaml
CHANGED
data/lib/uzuuzu/lang/ja.yaml
CHANGED
data/lib/uzuuzu/model.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module UzuUzu
|
4
|
+
module Model
|
5
|
+
#
|
6
|
+
AppsLoaded = {}
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
def const_missing(id)
|
11
|
+
AppsLoaded[::UzuUzu.current.name] ||= {}
|
12
|
+
model = AppsLoaded[::UzuUzu.current.name][id.to_sym]
|
13
|
+
unless model
|
14
|
+
require_base = self.name.gsub(/::/, '/').sub(/^UzuUzu/, 'uzuuzu').snake_case
|
15
|
+
require "#{require_base}/#{::UzuUzu.datastore.adapter}/#{id.to_s.snake_case}"
|
16
|
+
model = const_get("#{::UzuUzu.datastore.adapter.to_s.camel_case}").const_get("#{id}")
|
17
|
+
model.apploaded if model.respond_to?(:apploaded)
|
18
|
+
AppsLoaded[::UzuUzu.current.name][id.to_sym] = model
|
19
|
+
end
|
20
|
+
if model
|
21
|
+
model
|
22
|
+
else
|
23
|
+
super(id)
|
24
|
+
end
|
25
|
+
rescue => e
|
26
|
+
::UzuUzu.logger.debug e
|
27
|
+
::UzuUzu.logger.debug e.backtrace
|
28
|
+
super(id)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
#
|
33
|
+
#
|
34
|
+
def method_missing(id)
|
35
|
+
model = self.const_missing(id.to_s.camel_case)
|
36
|
+
if model
|
37
|
+
model
|
38
|
+
else
|
39
|
+
super(id)
|
40
|
+
end
|
41
|
+
rescue => e
|
42
|
+
::UzuUzu.logger.debug e
|
43
|
+
::UzuUzu.logger.debug e.backtrace
|
44
|
+
super(id)
|
45
|
+
end
|
46
|
+
|
47
|
+
extend self
|
48
|
+
end # Model
|
49
|
+
end # UzuUzu
|
data/lib/uzuuzu/response.rb
CHANGED
@@ -5,11 +5,127 @@ module UzuUzu
|
|
5
5
|
#
|
6
6
|
#
|
7
7
|
class Response < Rack::Response
|
8
|
+
include ::UzuUzu::Helper::Controller
|
9
|
+
|
8
10
|
#
|
9
11
|
#
|
10
12
|
#
|
11
13
|
def self.current
|
12
14
|
Thread.current[:response]
|
13
15
|
end
|
16
|
+
|
17
|
+
#
|
18
|
+
#
|
19
|
+
#
|
20
|
+
def rack_mime_type(type, value=nil)
|
21
|
+
return type if type.nil? || type.to_s.include?('/')
|
22
|
+
type = ".#{type}" unless type.to_s[0] == ?.
|
23
|
+
return Rack::Mime.mime_type(type, nil) if value.nil?
|
24
|
+
Rack::Mime::MIME_TYPES[type] = value
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
#
|
29
|
+
#
|
30
|
+
def mime_type(mime)
|
31
|
+
@header["Content-Type"] = rack_mime_type(mime) || mime if mime
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
#
|
36
|
+
#
|
37
|
+
def respond(string, mime=nil, status=200)
|
38
|
+
@status = 200
|
39
|
+
mime_type(mime)
|
40
|
+
write string
|
41
|
+
throw :finish
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
#
|
46
|
+
#
|
47
|
+
def respond_to
|
48
|
+
return unless block_given?
|
49
|
+
@status = 200
|
50
|
+
contents = yield(request.wish)
|
51
|
+
respond(contents, request.wish) if contents and successful?
|
52
|
+
end
|
53
|
+
|
54
|
+
def send_file()
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_binary()
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
#
|
64
|
+
#
|
65
|
+
def server_error(code=500, options={})
|
66
|
+
redirect "/error/#{code}"
|
67
|
+
end # error
|
68
|
+
|
69
|
+
#
|
70
|
+
#
|
71
|
+
#
|
72
|
+
def not_found(code=404, options={})
|
73
|
+
server_error(code, options)
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
#
|
78
|
+
#
|
79
|
+
def redirect(uri, options={})
|
80
|
+
if not uri =~ /^https?:\/\//
|
81
|
+
abs_uri = "#{request.scheme}://#{request.host}"
|
82
|
+
|
83
|
+
if request.scheme == 'https' && request.port != 443 ||
|
84
|
+
request.scheme == 'http' && request.port != 80
|
85
|
+
abs_uri << ":#{request.port}"
|
86
|
+
end
|
87
|
+
uri = (abs_uri << uri)
|
88
|
+
end
|
89
|
+
uri << query_string(options)
|
90
|
+
super(uri)
|
91
|
+
throw :finish
|
92
|
+
end # redirect
|
93
|
+
|
94
|
+
#
|
95
|
+
#
|
96
|
+
#
|
97
|
+
def last_modified(time)
|
98
|
+
return unless time
|
99
|
+
if time.respond_to?(:to_time)
|
100
|
+
time = time.to_time
|
101
|
+
else
|
102
|
+
time = ::Time.parse(time.to_s)
|
103
|
+
end
|
104
|
+
@header['Last-Modified'] = time.httpdate
|
105
|
+
if ::Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
|
106
|
+
@status = 304
|
107
|
+
throw :finish
|
108
|
+
end
|
109
|
+
end # last_modified
|
110
|
+
|
111
|
+
#
|
112
|
+
#
|
113
|
+
#
|
114
|
+
def etag(value, kind=:strong)
|
115
|
+
raise ::TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
|
116
|
+
value = '"%s"' % value
|
117
|
+
value = 'W/' + value if kind == :weak
|
118
|
+
@header['ETag'] = value
|
119
|
+
|
120
|
+
# Conditional GET check
|
121
|
+
if etags = request.env['HTTP_IF_NONE_MATCH']
|
122
|
+
etags = etags.split(/\s*,\s*/)
|
123
|
+
if etags.include?(value) || etags.include?('*')
|
124
|
+
@status = 304
|
125
|
+
throw :finish
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end # etag
|
129
|
+
|
14
130
|
end
|
15
131
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module UzuUzu
|
4
|
+
module Service
|
5
|
+
AppsLoaded = {}
|
6
|
+
#
|
7
|
+
#
|
8
|
+
#
|
9
|
+
def const_missing(id)
|
10
|
+
AppsLoaded[::UzuUzu.current.name] ||= {}
|
11
|
+
service = AppsLoaded[::UzuUzu.current.name][id.to_sym]
|
12
|
+
unless service
|
13
|
+
require_base = self.name.gsub(/::/, '/').sub(/^UzuUzu/, 'uzuuzu').snake_case
|
14
|
+
require "#{require_base}/#{::UzuUzu.datastore.adapter}/#{id.to_s.snake_case}"
|
15
|
+
service = const_get("#{::UzuUzu.datastore.adapter.to_s.camel_case}").const_get("#{id}")
|
16
|
+
service.apploaded if service.respond_to?(:apsploaded)
|
17
|
+
AppsLoaded[::UzuUzu.current.name][id.to_sym] = service
|
18
|
+
end
|
19
|
+
if service
|
20
|
+
service
|
21
|
+
else
|
22
|
+
super(id)
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
::UzuUzu.logger.debug e
|
26
|
+
::UzuUzu.logger.debug e.backtrace
|
27
|
+
super(id)
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
#
|
32
|
+
#
|
33
|
+
def method_missing(id)
|
34
|
+
service = const_missing(id.to_s.camel_case)
|
35
|
+
if service
|
36
|
+
service.new
|
37
|
+
else
|
38
|
+
super(id)
|
39
|
+
end
|
40
|
+
rescue => e
|
41
|
+
::UzuUzu.logger.debug e
|
42
|
+
::UzuUzu.logger.debug e.backtrace
|
43
|
+
super(id)
|
44
|
+
end
|
45
|
+
|
46
|
+
extend self
|
47
|
+
end # Service
|
48
|
+
end # UzuUzu
|
@@ -62,6 +62,30 @@ module UzuUzu
|
|
62
62
|
Environments.current.localize
|
63
63
|
end
|
64
64
|
|
65
|
+
def controller
|
66
|
+
Controller.current
|
67
|
+
end
|
68
|
+
|
69
|
+
def helper
|
70
|
+
Helper.current
|
71
|
+
end
|
72
|
+
|
73
|
+
def request
|
74
|
+
Request.current
|
75
|
+
end
|
76
|
+
|
77
|
+
def response
|
78
|
+
Response.current
|
79
|
+
end
|
80
|
+
|
81
|
+
def model
|
82
|
+
Model
|
83
|
+
end
|
84
|
+
|
85
|
+
def service
|
86
|
+
Service
|
87
|
+
end
|
88
|
+
|
65
89
|
#
|
66
90
|
def render_engine(instance, view_string, engine='erb', options={}, locals={}, &block)
|
67
91
|
Tilt.render_engine(instance, view_string, engine, options, locals, &block)
|
data/lib/uzuuzu_core.rb
CHANGED
@@ -12,8 +12,10 @@ require 'uzuuzu/wrapper/logger'
|
|
12
12
|
require 'uzuuzu/wrapper/wrapper'
|
13
13
|
require 'uzuuzu/application'
|
14
14
|
require 'uzuuzu/environments'
|
15
|
+
require 'uzuuzu/helper'
|
15
16
|
require 'uzuuzu/request'
|
16
17
|
require 'uzuuzu/response'
|
17
|
-
require 'uzuuzu/helper'
|
18
18
|
require 'uzuuzu/controller'
|
19
|
+
require 'uzuuzu/service'
|
20
|
+
require 'uzuuzu/model'
|
19
21
|
require 'uzuuzu/tilt'
|
data/uzuuzu-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{uzuuzu-core}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Takuya Kondo"]
|
12
|
-
s.date = %q{2011-09-
|
12
|
+
s.date = %q{2011-09-24}
|
13
13
|
s.description = %q{uzuuzu core library}
|
14
14
|
s.email = %q{takuya.v3v@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -36,7 +36,6 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/uzuuzu/datastore/sequel.rb",
|
37
37
|
"lib/uzuuzu/environments.rb",
|
38
38
|
"lib/uzuuzu/ext/object.rb",
|
39
|
-
"lib/uzuuzu/fixture/datamapper.rb",
|
40
39
|
"lib/uzuuzu/helper.rb",
|
41
40
|
"lib/uzuuzu/helper/controller.rb",
|
42
41
|
"lib/uzuuzu/helper/form.rb",
|
@@ -44,7 +43,6 @@ Gem::Specification.new do |s|
|
|
44
43
|
"lib/uzuuzu/helper/localize.rb",
|
45
44
|
"lib/uzuuzu/helper/renderer.rb",
|
46
45
|
"lib/uzuuzu/helper/route.rb",
|
47
|
-
"lib/uzuuzu/helper/uzuuzu.rb",
|
48
46
|
"lib/uzuuzu/helper/xhtml.rb",
|
49
47
|
"lib/uzuuzu/kvs/appengine.rb",
|
50
48
|
"lib/uzuuzu/kvs/hbase.rb",
|
@@ -63,12 +61,14 @@ Gem::Specification.new do |s|
|
|
63
61
|
"lib/uzuuzu/memcache/dalli.rb",
|
64
62
|
"lib/uzuuzu/memcache/leveldb.rb",
|
65
63
|
"lib/uzuuzu/memcache/memcached.rb",
|
64
|
+
"lib/uzuuzu/model.rb",
|
66
65
|
"lib/uzuuzu/rack_session/appengine.rb",
|
67
66
|
"lib/uzuuzu/rack_session/cookie.rb",
|
68
67
|
"lib/uzuuzu/rack_session/datastore.rb",
|
69
68
|
"lib/uzuuzu/rack_session/memcache.rb",
|
70
69
|
"lib/uzuuzu/request.rb",
|
71
70
|
"lib/uzuuzu/response.rb",
|
71
|
+
"lib/uzuuzu/service.rb",
|
72
72
|
"lib/uzuuzu/tilt.rb",
|
73
73
|
"lib/uzuuzu/wrapper/logger.rb",
|
74
74
|
"lib/uzuuzu/wrapper/uzuuzu.rb",
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: uzuuzu-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Takuya Kondo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-24 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -141,7 +141,6 @@ files:
|
|
141
141
|
- lib/uzuuzu/datastore/sequel.rb
|
142
142
|
- lib/uzuuzu/environments.rb
|
143
143
|
- lib/uzuuzu/ext/object.rb
|
144
|
-
- lib/uzuuzu/fixture/datamapper.rb
|
145
144
|
- lib/uzuuzu/helper.rb
|
146
145
|
- lib/uzuuzu/helper/controller.rb
|
147
146
|
- lib/uzuuzu/helper/form.rb
|
@@ -149,7 +148,6 @@ files:
|
|
149
148
|
- lib/uzuuzu/helper/localize.rb
|
150
149
|
- lib/uzuuzu/helper/renderer.rb
|
151
150
|
- lib/uzuuzu/helper/route.rb
|
152
|
-
- lib/uzuuzu/helper/uzuuzu.rb
|
153
151
|
- lib/uzuuzu/helper/xhtml.rb
|
154
152
|
- lib/uzuuzu/kvs/appengine.rb
|
155
153
|
- lib/uzuuzu/kvs/hbase.rb
|
@@ -168,12 +166,14 @@ files:
|
|
168
166
|
- lib/uzuuzu/memcache/dalli.rb
|
169
167
|
- lib/uzuuzu/memcache/leveldb.rb
|
170
168
|
- lib/uzuuzu/memcache/memcached.rb
|
169
|
+
- lib/uzuuzu/model.rb
|
171
170
|
- lib/uzuuzu/rack_session/appengine.rb
|
172
171
|
- lib/uzuuzu/rack_session/cookie.rb
|
173
172
|
- lib/uzuuzu/rack_session/datastore.rb
|
174
173
|
- lib/uzuuzu/rack_session/memcache.rb
|
175
174
|
- lib/uzuuzu/request.rb
|
176
175
|
- lib/uzuuzu/response.rb
|
176
|
+
- lib/uzuuzu/service.rb
|
177
177
|
- lib/uzuuzu/tilt.rb
|
178
178
|
- lib/uzuuzu/wrapper/logger.rb
|
179
179
|
- lib/uzuuzu/wrapper/uzuuzu.rb
|
@@ -196,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
196
|
requirements:
|
197
197
|
- - ">="
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
hash:
|
199
|
+
hash: 3259301030999928627
|
200
200
|
segments:
|
201
201
|
- 0
|
202
202
|
version: "0"
|
@@ -1,114 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module UzuUzu
|
4
|
-
module DataStore
|
5
|
-
module Fixture
|
6
|
-
def self.import_file(model, file, overwrite=false)
|
7
|
-
unless ::File.file?(file)
|
8
|
-
raise "UzuUzu fixture import error file not found : #{file}"
|
9
|
-
end
|
10
|
-
ext = ::File.extname(file)
|
11
|
-
case(ext)
|
12
|
-
when '.yml', '.yaml'
|
13
|
-
import_yaml(model, ::YAML.load_file(file), overwrite)
|
14
|
-
when '.xml'
|
15
|
-
# TODO
|
16
|
-
when '.json', '.js'
|
17
|
-
# TODO
|
18
|
-
when '.csv'
|
19
|
-
begin
|
20
|
-
require 'fastercsv'
|
21
|
-
::FasterCSV.foreach(file) do |row|
|
22
|
-
import_csv(model, row, overwrite)
|
23
|
-
end
|
24
|
-
rescue
|
25
|
-
require "csv"
|
26
|
-
::CSV.open(file) do |row|
|
27
|
-
import_csv(model, row, overwrite)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.import_yaml(model, yaml, overwrite=false)
|
35
|
-
::UzuUzu.logger.debug 'import yaml'
|
36
|
-
::UzuUzu.transaction do |tr|
|
37
|
-
tr.begin
|
38
|
-
begin
|
39
|
-
if yaml.kind_of?(Array)
|
40
|
-
yaml.each do |map|
|
41
|
-
::UzuUzu.logger.debug "import #{map.inspect}"
|
42
|
-
resource = model.first(:id => map[:id]) unless map[:id].nil?
|
43
|
-
if resource.nil?
|
44
|
-
resource = model.new(map)
|
45
|
-
unless resource.valid?
|
46
|
-
::UzuUzu.logger.error resource.errors
|
47
|
-
end
|
48
|
-
resource.save
|
49
|
-
elsif overwrite
|
50
|
-
resource.update(map)
|
51
|
-
unless resource.valid?
|
52
|
-
::UzuUzu.logger.error resource.errors
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
elsif yaml.kind_of?(Hash)
|
57
|
-
::UzuUzu.logger.debug "import #{yaml.inspect}"
|
58
|
-
resource = model.first(:id => yaml[:id]) unless yaml[:id].nil?
|
59
|
-
if resource.nil?
|
60
|
-
resource = model.new(yaml)
|
61
|
-
unless resource.valid?
|
62
|
-
::UzuUzu.logger.error resource.errors
|
63
|
-
end
|
64
|
-
resource.save
|
65
|
-
elsif overwrite
|
66
|
-
resource.update(yaml)
|
67
|
-
unless resource.valid?
|
68
|
-
::UzuUzu.logger.error resource.errors
|
69
|
-
end
|
70
|
-
end
|
71
|
-
else
|
72
|
-
::UzuUzu.logger.error "import type miss match #{yaml.inspect}"
|
73
|
-
end
|
74
|
-
::UzuUzu.logger.debug 'imported yaml'
|
75
|
-
tr.commit
|
76
|
-
rescue => e
|
77
|
-
tr.rollback
|
78
|
-
raise e
|
79
|
-
end
|
80
|
-
end # transaction
|
81
|
-
end # import_yaml
|
82
|
-
|
83
|
-
def self.import_json(model, json, overwrite=false)
|
84
|
-
# TODO
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.import_xml(model, xml, overwrite=false)
|
88
|
-
# TODO
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.import_csv(model, csv, overwrite=false)
|
92
|
-
::UzuUzu.transaction do |tr|
|
93
|
-
tr.begin
|
94
|
-
begin
|
95
|
-
resource = model.first(:id => csv[0])
|
96
|
-
csv.each_with_index do |culumn, index|
|
97
|
-
if resource.nil? || overwrite
|
98
|
-
resource ||= model.new
|
99
|
-
resource.properties.each_with_index do |property, column_no|
|
100
|
-
resource[property.name] = culumn if index = column_no
|
101
|
-
end
|
102
|
-
resource.save
|
103
|
-
end
|
104
|
-
end
|
105
|
-
tr.commit
|
106
|
-
rescue => e
|
107
|
-
tr.rollback
|
108
|
-
raise e
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end # import_csv
|
112
|
-
end # Fixture
|
113
|
-
end # DataStore
|
114
|
-
end # UzuUzu
|
data/lib/uzuuzu/helper/uzuuzu.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module UzuUzu
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
module Helper
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
module UzuUzuHelper
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
def logger
|
16
|
-
::UzuUzu.logger
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
def memcache
|
23
|
-
::UzuUzu.memcache
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
def kvs
|
30
|
-
::UzuUzu.kvs
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
def datastore
|
37
|
-
::UzuUzu.datastore
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
def mailer
|
44
|
-
::UzuUzu.mailer
|
45
|
-
end
|
46
|
-
end # UzuUzuHelper
|
47
|
-
end # Helper
|
48
|
-
end # UzuUzu
|