tzispa 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/lib/tzispa/api/handler.rb +54 -23
  4. data/lib/tzispa/app.rb +60 -68
  5. data/lib/tzispa/cli.rb +42 -3
  6. data/lib/tzispa/commands/api.rb +55 -0
  7. data/lib/tzispa/commands/app.rb +83 -0
  8. data/lib/tzispa/commands/cli/generate.rb +60 -0
  9. data/lib/tzispa/commands/command.rb +28 -0
  10. data/lib/tzispa/commands/console.rb +62 -0
  11. data/lib/tzispa/commands/helpers/i18n.rb +67 -0
  12. data/lib/tzispa/commands/helpers/project.rb +69 -0
  13. data/lib/tzispa/commands/helpers/repository.rb +46 -0
  14. data/lib/tzispa/commands/project.rb +104 -0
  15. data/lib/tzispa/commands/repository.rb +66 -0
  16. data/lib/tzispa/commands/rig.rb +28 -0
  17. data/lib/tzispa/commands/server.rb +26 -0
  18. data/lib/tzispa/config/{appconfig.rb → app_config.rb} +12 -32
  19. data/lib/tzispa/config/base.rb +7 -5
  20. data/lib/tzispa/config/db_config.rb +67 -0
  21. data/lib/tzispa/config/yaml.rb +9 -10
  22. data/lib/tzispa/context.rb +3 -2
  23. data/lib/tzispa/controller/api.rb +66 -60
  24. data/lib/tzispa/controller/auth_layout.rb +4 -28
  25. data/lib/tzispa/controller/base.rb +61 -24
  26. data/lib/tzispa/controller/exceptions.rb +3 -4
  27. data/lib/tzispa/controller/http_error.rb +0 -3
  28. data/lib/tzispa/controller/layout.rb +4 -4
  29. data/lib/tzispa/domain.rb +27 -23
  30. data/lib/tzispa/env.rb +34 -0
  31. data/lib/tzispa/environment.rb +231 -0
  32. data/lib/tzispa/http/context.rb +65 -80
  33. data/lib/tzispa/http/request.rb +29 -17
  34. data/lib/tzispa/http/response.rb +45 -12
  35. data/lib/tzispa/route_set.rb +100 -0
  36. data/lib/tzispa/server.rb +61 -0
  37. data/lib/tzispa/tzisparc.rb +80 -0
  38. data/lib/tzispa/version.rb +1 -1
  39. data/lib/tzispa.rb +3 -1
  40. data/tzispa.gemspec +12 -6
  41. metadata +68 -17
  42. data/lib/tzispa/command/api.rb +0 -24
  43. data/lib/tzispa/command/app.rb +0 -95
  44. data/lib/tzispa/command/cli/generate.rb +0 -51
  45. data/lib/tzispa/command/project.rb +0 -258
  46. data/lib/tzispa/command/rig.rb +0 -26
  47. data/lib/tzispa/controller/signed_api.rb +0 -13
  48. data/lib/tzispa/http/session_flash_bag.rb +0 -62
  49. data/lib/tzispa/middleware.rb +0 -48
  50. data/lib/tzispa/routes.rb +0 -69
@@ -1,258 +0,0 @@
1
- require 'json'
2
- require "base64"
3
-
4
- module Tzispa
5
- module Command
6
-
7
- class Project
8
-
9
- PROJECT_STRUCTURE = [
10
- 'apps',
11
- 'config',
12
- 'config/locales',
13
- 'data',
14
- 'data/session',
15
- 'logs',
16
- 'public',
17
- 'public/css',
18
- 'public/css/fonts',
19
- 'public/css/less',
20
- 'public/img',
21
- 'public/js',
22
- 'repository',
23
- 'tmp'
24
- ]
25
-
26
- PROJECT_FILE = '.tzispaprj'
27
- START_FILE = 'start.ru'
28
- PUMA_CONFIG_FILE = 'puma.rb'
29
-
30
- DEFAULT_MOUNT_PATH = '/'
31
-
32
- attr_accessor :name, :apps, :created
33
-
34
- def initialize(name)
35
- @name = name
36
- @apps = Array.new
37
- end
38
-
39
-
40
- def generate
41
- if create_structure
42
- create_project
43
- create_start
44
- create_pumaconfig
45
- create_i18n 'en'
46
- end
47
- end
48
-
49
- def self.check?
50
- File.exist? "#{PROJECT_FILE}"
51
- end
52
-
53
- def self.open
54
- raise "This command must be runned in a Tzispa project base dir" unless self.check?
55
- hpj = JSON.parse String.new.tap { |ptxt|
56
- File.open("#{PROJECT_FILE}","r") do |f|
57
- while line = f.gets
58
- ptxt << line
59
- end
60
- end
61
- }
62
- self.new(hpj['name']).tap { |project|
63
- project.apps = hpj['apps']
64
- project.created = hpj['created']
65
- }
66
- end
67
-
68
- def close
69
- save to_h
70
- end
71
-
72
- def to_h
73
- Hash.new.tap { |h|
74
- h['name'] = name
75
- h['apps'] = apps
76
- h['created'] = created
77
- }
78
- end
79
-
80
- private
81
-
82
- def save(prj, base_dir=nil)
83
- base_dir = "#{base_dir}/" if base_dir
84
- File.open("#{base_dir}#{PROJECT_FILE}","w") do |f|
85
- f.write prj.to_json
86
- end
87
- end
88
-
89
- def create_structure
90
- unless File.exist? name
91
- Dir.mkdir "#{name}"
92
- PROJECT_STRUCTURE.each { |psdir|
93
- Dir.mkdir "#{name}/#{psdir}"
94
- }
95
- end
96
- end
97
-
98
- def create_project
99
- save({
100
- name: name,
101
- created: Time.new,
102
- apps: []
103
- }, name)
104
- end
105
-
106
- def create_start
107
- File.open("#{name}/#{START_FILE}","w") do |f|
108
- f.puts "require 'tzispa'\n\n"
109
- end
110
- end
111
-
112
- def create_pumaconfig
113
- File.open("#{name}/config/#{PUMA_CONFIG_FILE}", "w") do |f|
114
- f.puts PUMA_CONFIG
115
- end
116
- end
117
-
118
- def create_i18n(lang)
119
- File.open("#{name}/config/locales/#{lang}.yml", "w") do |f|
120
- f.puts Base64.decode64(I18N_DEFAULTS)
121
- end
122
- end
123
-
124
- PUMA_CONFIG = <<-PUMACONFIG
125
- #!/usr/bin/env puma
126
-
127
- #daemonize true
128
- pidfile 'puma.pid'
129
- state_path 'puma.state'
130
-
131
- # stdout_redirect 'logs/puma.stdout', 'logs/puma.stderr'
132
- # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true
133
-
134
- # Disable request logging.
135
- # quiet
136
-
137
- # threads 0, 16
138
-
139
-
140
- bind 'tcp://0.0.0.0:9292'
141
- workers 0
142
-
143
- on_restart do
144
- require 'fileutils'
145
- FileUtils.rm_rf(Dir.glob('./data/session/*'))
146
- end
147
-
148
- # on_worker_boot do
149
- # puts 'On worker boot...'
150
- # end
151
-
152
- # after_worker_boot do
153
- # puts 'On worker boot...'
154
- # end
155
-
156
- # on_worker_shutdown do
157
- # puts 'On worker boot...'
158
- # end
159
-
160
-
161
- tag 'your_app_tag'
162
- worker_timeout 90
163
- PUMACONFIG
164
-
165
- I18N_DEFAULTS = <<-I18NDEFAULTSBASE64
166
- LS0tDQplbjoNCiAgZGF0ZToNCiAgICBhYmJyX2RheV9uYW1lczoNCiAgICAtIFN1bg0KICAgIC0g
167
- TW9uDQogICAgLSBUdWUNCiAgICAtIFdlZA0KICAgIC0gVGh1DQogICAgLSBGcmkNCiAgICAtIFNh
168
- dA0KICAgIGFiYnJfbW9udGhfbmFtZXM6DQogICAgLQ0KICAgIC0gSmFuDQogICAgLSBGZWINCiAg
169
- ICAtIE1hcg0KICAgIC0gQXByDQogICAgLSBNYXkNCiAgICAtIEp1bg0KICAgIC0gSnVsDQogICAg
170
- LSBBdWcNCiAgICAtIFNlcA0KICAgIC0gT2N0DQogICAgLSBOb3YNCiAgICAtIERlYw0KICAgIGRh
171
- eV9uYW1lczoNCiAgICAtIFN1bmRheQ0KICAgIC0gTW9uZGF5DQogICAgLSBUdWVzZGF5DQogICAg
172
- LSBXZWRuZXNkYXkNCiAgICAtIFRodXJzZGF5DQogICAgLSBGcmlkYXkNCiAgICAtIFNhdHVyZGF5
173
- DQogICAgZm9ybWF0czoNCiAgICAgIGRlZmF1bHQ6ICIlWS0lbS0lZCINCiAgICAgIGxvbmc6ICIl
174
- QiAlZCwgJVkiDQogICAgICBzaG9ydDogIiViICVkIg0KICAgIG1vbnRoX25hbWVzOg0KICAgIC0N
175
- CiAgICAtIEphbnVhcnkNCiAgICAtIEZlYnJ1YXJ5DQogICAgLSBNYXJjaA0KICAgIC0gQXByaWwN
176
- CiAgICAtIE1heQ0KICAgIC0gSnVuZQ0KICAgIC0gSnVseQ0KICAgIC0gQXVndXN0DQogICAgLSBT
177
- ZXB0ZW1iZXINCiAgICAtIE9jdG9iZXINCiAgICAtIE5vdmVtYmVyDQogICAgLSBEZWNlbWJlcg0K
178
- ICAgIG9yZGVyOg0KICAgIC0gOnllYXINCiAgICAtIDptb250aA0KICAgIC0gOmRheQ0KICBkYXRl
179
- dGltZToNCiAgICBkaXN0YW5jZV9pbl93b3JkczoNCiAgICAgIGFib3V0X3hfaG91cnM6DQogICAg
180
- ICAgIG9uZTogYWJvdXQgMSBob3VyDQogICAgICAgIG90aGVyOiBhYm91dCAle2NvdW50fSBob3Vy
181
- cw0KICAgICAgYWJvdXRfeF9tb250aHM6DQogICAgICAgIG9uZTogYWJvdXQgMSBtb250aA0KICAg
182
- ICAgICBvdGhlcjogYWJvdXQgJXtjb3VudH0gbW9udGhzDQogICAgICBhYm91dF94X3llYXJzOg0K
183
- ICAgICAgICBvbmU6IGFib3V0IDEgeWVhcg0KICAgICAgICBvdGhlcjogYWJvdXQgJXtjb3VudH0g
184
- eWVhcnMNCiAgICAgIGFsbW9zdF94X3llYXJzOg0KICAgICAgICBvbmU6IGFsbW9zdCAxIHllYXIN
185
- CiAgICAgICAgb3RoZXI6IGFsbW9zdCAle2NvdW50fSB5ZWFycw0KICAgICAgaGFsZl9hX21pbnV0
186
- ZTogaGFsZiBhIG1pbnV0ZQ0KICAgICAgbGVzc190aGFuX3hfbWludXRlczoNCiAgICAgICAgb25l
187
- OiBsZXNzIHRoYW4gYSBtaW51dGUNCiAgICAgICAgb3RoZXI6IGxlc3MgdGhhbiAle2NvdW50fSBt
188
- aW51dGVzDQogICAgICBsZXNzX3RoYW5feF9zZWNvbmRzOg0KICAgICAgICBvbmU6IGxlc3MgdGhh
189
- biAxIHNlY29uZA0KICAgICAgICBvdGhlcjogbGVzcyB0aGFuICV7Y291bnR9IHNlY29uZHMNCiAg
190
- ICAgIG92ZXJfeF95ZWFyczoNCiAgICAgICAgb25lOiBvdmVyIDEgeWVhcg0KICAgICAgICBvdGhl
191
- cjogb3ZlciAle2NvdW50fSB5ZWFycw0KICAgICAgeF9kYXlzOg0KICAgICAgICBvbmU6IDEgZGF5
192
- DQogICAgICAgIG90aGVyOiAiJXtjb3VudH0gZGF5cyINCiAgICAgIHhfbWludXRlczoNCiAgICAg
193
- ICAgb25lOiAxIG1pbnV0ZQ0KICAgICAgICBvdGhlcjogIiV7Y291bnR9IG1pbnV0ZXMiDQogICAg
194
- ICB4X21vbnRoczoNCiAgICAgICAgb25lOiAxIG1vbnRoDQogICAgICAgIG90aGVyOiAiJXtjb3Vu
195
- dH0gbW9udGhzIg0KICAgICAgeF9zZWNvbmRzOg0KICAgICAgICBvbmU6IDEgc2Vjb25kDQogICAg
196
- ICAgIG90aGVyOiAiJXtjb3VudH0gc2Vjb25kcyINCiAgICBwcm9tcHRzOg0KICAgICAgZGF5OiBE
197
- YXkNCiAgICAgIGhvdXI6IEhvdXINCiAgICAgIG1pbnV0ZTogTWludXRlDQogICAgICBtb250aDog
198
- TW9udGgNCiAgICAgIHNlY29uZDogU2Vjb25kcw0KICAgICAgeWVhcjogWWVhcg0KICBlcnJvcnM6
199
- DQogICAgZm9ybWF0OiAiJXthdHRyaWJ1dGV9ICV7bWVzc2FnZX0iDQogICAgbWVzc2FnZXM6DQog
200
- ICAgICBhY2NlcHRlZDogbXVzdCBiZSBhY2NlcHRlZA0KICAgICAgYmxhbms6IGNhbid0IGJlIGJs
201
- YW5rDQogICAgICBwcmVzZW50OiBtdXN0IGJlIGJsYW5rDQogICAgICBjb25maXJtYXRpb246IGRv
202
- ZXNuJ3QgbWF0Y2ggJXthdHRyaWJ1dGV9DQogICAgICBlbXB0eTogY2FuJ3QgYmUgZW1wdHkNCiAg
203
- ICAgIGVxdWFsX3RvOiBtdXN0IGJlIGVxdWFsIHRvICV7Y291bnR9DQogICAgICBldmVuOiBtdXN0
204
- IGJlIGV2ZW4NCiAgICAgIGV4Y2x1c2lvbjogaXMgcmVzZXJ2ZWQNCiAgICAgIGdyZWF0ZXJfdGhh
205
- bjogbXVzdCBiZSBncmVhdGVyIHRoYW4gJXtjb3VudH0NCiAgICAgIGdyZWF0ZXJfdGhhbl9vcl9l
206
- cXVhbF90bzogbXVzdCBiZSBncmVhdGVyIHRoYW4gb3IgZXF1YWwgdG8gJXtjb3VudH0NCiAgICAg
207
- IGluY2x1c2lvbjogaXMgbm90IGluY2x1ZGVkIGluIHRoZSBsaXN0DQogICAgICBpbnZhbGlkOiBp
208
- cyBpbnZhbGlkDQogICAgICBsZXNzX3RoYW46IG11c3QgYmUgbGVzcyB0aGFuICV7Y291bnR9DQog
209
- ICAgICBsZXNzX3RoYW5fb3JfZXF1YWxfdG86IG11c3QgYmUgbGVzcyB0aGFuIG9yIGVxdWFsIHRv
210
- ICV7Y291bnR9DQogICAgICBtb2RlbF9pbnZhbGlkOiAiVmFsaWRhdGlvbiBmYWlsZWQ6ICV7ZXJy
211
- b3JzfSINCiAgICAgIG5vdF9hX251bWJlcjogaXMgbm90IGEgbnVtYmVyDQogICAgICBub3RfYW5f
212
- aW50ZWdlcjogbXVzdCBiZSBhbiBpbnRlZ2VyDQogICAgICBvZGQ6IG11c3QgYmUgb2RkDQogICAg
213
- ICByZXF1aXJlZDogbXVzdCBleGlzdA0KICAgICAgdGFrZW46IGhhcyBhbHJlYWR5IGJlZW4gdGFr
214
- ZW4NCiAgICAgIHRvb19sb25nOg0KICAgICAgICBvbmU6IGlzIHRvbyBsb25nIChtYXhpbXVtIGlz
215
- IDEgY2hhcmFjdGVyKQ0KICAgICAgICBvdGhlcjogaXMgdG9vIGxvbmcgKG1heGltdW0gaXMgJXtj
216
- b3VudH0gY2hhcmFjdGVycykNCiAgICAgIHRvb19zaG9ydDoNCiAgICAgICAgb25lOiBpcyB0b28g
217
- c2hvcnQgKG1pbmltdW0gaXMgMSBjaGFyYWN0ZXIpDQogICAgICAgIG90aGVyOiBpcyB0b28gc2hv
218
- cnQgKG1pbmltdW0gaXMgJXtjb3VudH0gY2hhcmFjdGVycykNCiAgICAgIHdyb25nX2xlbmd0aDoN
219
- CiAgICAgICAgb25lOiBpcyB0aGUgd3JvbmcgbGVuZ3RoIChzaG91bGQgYmUgMSBjaGFyYWN0ZXIp
220
- DQogICAgICAgIG90aGVyOiBpcyB0aGUgd3JvbmcgbGVuZ3RoIChzaG91bGQgYmUgJXtjb3VudH0g
221
- Y2hhcmFjdGVycykNCiAgICAgIG90aGVyX3RoYW46IG11c3QgYmUgb3RoZXIgdGhhbiAle2NvdW50
222
- fQ0KICAgIHRlbXBsYXRlOg0KICAgICAgYm9keTogJ1RoZXJlIHdlcmUgcHJvYmxlbXMgd2l0aCB0
223
- aGUgZm9sbG93aW5nIGZpZWxkczonDQogICAgICBoZWFkZXI6DQogICAgICAgIG9uZTogMSBlcnJv
224
- ciBwcm9oaWJpdGVkIHRoaXMgJXttb2RlbH0gZnJvbSBiZWluZyBzYXZlZA0KICAgICAgICBvdGhl
225
- cjogIiV7Y291bnR9IGVycm9ycyBwcm9oaWJpdGVkIHRoaXMgJXttb2RlbH0gZnJvbSBiZWluZyBz
226
- YXZlZCINCiAgaGVscGVyczoNCiAgICBzZWxlY3Q6DQogICAgICBwcm9tcHQ6IFBsZWFzZSBzZWxl
227
- Y3QNCiAgICBzdWJtaXQ6DQogICAgICBjcmVhdGU6IENyZWF0ZSAle21vZGVsfQ0KICAgICAgc3Vi
228
- bWl0OiBTYXZlICV7bW9kZWx9DQogICAgICB1cGRhdGU6IFVwZGF0ZSAle21vZGVsfQ0KICBudW1i
229
- ZXI6DQogICAgY3VycmVuY3k6DQogICAgICBmb3JtYXQ6DQogICAgICAgIGRlbGltaXRlcjogIiwi
230
- DQogICAgICAgIGZvcm1hdDogIiV1JW4iDQogICAgICAgIHByZWNpc2lvbjogMg0KICAgICAgICBz
231
- ZXBhcmF0b3I6ICIuIg0KICAgICAgICBzaWduaWZpY2FudDogZmFsc2UNCiAgICAgICAgc3RyaXBf
232
- aW5zaWduaWZpY2FudF96ZXJvczogZmFsc2UNCiAgICAgICAgdW5pdDogIiQiDQogICAgZm9ybWF0
233
- Og0KICAgICAgZGVsaW1pdGVyOiAiLCINCiAgICAgIHByZWNpc2lvbjogMw0KICAgICAgc2VwYXJh
234
- dG9yOiAiLiINCiAgICAgIHNpZ25pZmljYW50OiBmYWxzZQ0KICAgICAgc3RyaXBfaW5zaWduaWZp
235
- Y2FudF96ZXJvczogZmFsc2UNCiAgICBodW1hbjoNCiAgICAgIGRlY2ltYWxfdW5pdHM6DQogICAg
236
- ICAgIGZvcm1hdDogIiVuICV1Ig0KICAgICAgICB1bml0czoNCiAgICAgICAgICBiaWxsaW9uOiBC
237
- aWxsaW9uDQogICAgICAgICAgbWlsbGlvbjogTWlsbGlvbg0KICAgICAgICAgIHF1YWRyaWxsaW9u
238
- OiBRdWFkcmlsbGlvbg0KICAgICAgICAgIHRob3VzYW5kOiBUaG91c2FuZA0KICAgICAgICAgIHRy
239
- aWxsaW9uOiBUcmlsbGlvbg0KICAgICAgICAgIHVuaXQ6ICcnDQogICAgICBmb3JtYXQ6DQogICAg
240
- ICAgIGRlbGltaXRlcjogJycNCiAgICAgICAgcHJlY2lzaW9uOiAzDQogICAgICAgIHNpZ25pZmlj
241
- YW50OiB0cnVlDQogICAgICAgIHN0cmlwX2luc2lnbmlmaWNhbnRfemVyb3M6IHRydWUNCiAgICAg
242
- IHN0b3JhZ2VfdW5pdHM6DQogICAgICAgIGZvcm1hdDogIiVuICV1Ig0KICAgICAgICB1bml0czoN
243
- CiAgICAgICAgICBieXRlOg0KICAgICAgICAgICAgb25lOiBCeXRlDQogICAgICAgICAgICBvdGhl
244
- cjogQnl0ZXMNCiAgICAgICAgICBnYjogR0INCiAgICAgICAgICBrYjogS0INCiAgICAgICAgICBt
245
- YjogTUINCiAgICAgICAgICB0YjogVEINCiAgICBwZXJjZW50YWdlOg0KICAgICAgZm9ybWF0Og0K
246
- ICAgICAgICBkZWxpbWl0ZXI6ICcnDQogICAgICAgIGZvcm1hdDogIiVuJSINCiAgICBwcmVjaXNp
247
- b246DQogICAgICBmb3JtYXQ6DQogICAgICAgIGRlbGltaXRlcjogJycNCiAgdGltZToNCiAgICBh
248
- bTogYW0NCiAgICBmb3JtYXRzOg0KICAgICAgZGVmYXVsdDogIiVhLCAlZCAlYiAlWSAlSDolTTol
249
- UyAleiINCiAgICAgIGxvbmc6ICIlQiAlZCwgJVkgJUg6JU0iDQogICAgICBzaG9ydDogIiVkICVi
250
- ICVIOiVNIg0KICAgIHBtOiBwbQ0K
251
- I18NDEFAULTSBASE64
252
-
253
-
254
- end
255
-
256
-
257
- end
258
- end
@@ -1,26 +0,0 @@
1
- require 'tzispa/rig/template'
2
-
3
- module Tzispa
4
- module Command
5
-
6
- class Rig
7
-
8
- attr_reader :name, :domain, :type, :mime_format
9
-
10
- def initialize(name, app, type, mime_format = nil)
11
- @prj = Project.open
12
- raise "Application '#{app}' does not exists in project file" unless @prj.apps.include?(app)
13
- @domain = Tzispa::Domain.new app
14
- @type = type.to_sym
15
- @name = name
16
- @mime_format = mime_format
17
- end
18
-
19
- def generate
20
- Tzispa::Rig::Template.new(name: name, type: type, domain: domain, format: mime_format).create
21
- end
22
-
23
- end
24
-
25
- end
26
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'tzispa/controller/api'
3
- require 'tzispa/helpers/security'
4
-
5
- module Tzispa
6
- module Controller
7
- class SignedApi < Api
8
-
9
- # deprecated !!
10
-
11
- end
12
- end
13
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module Tzispa
6
- module Http
7
-
8
- class SessionFlashBag
9
-
10
-
11
- extend Forwardable
12
-
13
- def_delegators :@bag, :count, :length, :size, :each
14
-
15
- SESSION_FLASH_BAG = :__flash_bag
16
-
17
- def initialize(session, key)
18
- @session = session
19
- @session_key = "#{SESSION_FLASH_BAG}_#{key}".to_sym
20
- load!
21
- end
22
-
23
- def <<(value)
24
- if not value.nil?
25
- @bag << value
26
- store
27
- end
28
- end
29
-
30
- def pop
31
- value = @bag.pop
32
- store
33
- value
34
- end
35
-
36
- def pop_all
37
- empty!
38
- @bag
39
- end
40
-
41
- def push(value)
42
- @bag.push value
43
- store
44
- end
45
-
46
- private
47
-
48
- def load!
49
- @bag = @session[@session_key] ? Marshal.load(@session[@session_key]) : Array.new
50
- end
51
-
52
- def store
53
- @session[@session_key] = Marshal.dump @bag
54
- end
55
-
56
- def empty!
57
- @session[@session_key] = Array.new
58
- end
59
-
60
- end
61
- end
62
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tzispa/http/context'
4
-
5
- module Tzispa
6
-
7
- class Middleware
8
-
9
- attr_reader :application, :stack
10
-
11
- def initialize(app)
12
- @stack = []
13
- @application = app
14
- end
15
-
16
- def builder
17
- midw = self
18
- @builder ||= ::Rack::Builder.new do
19
- #mw.load_default_stack
20
- midw.application.load!
21
- midw.stack.each { |m, args, block| use midw.load(m), *args, &block }
22
- run midw.application.routes.router
23
- end
24
- end
25
-
26
- def use(middleware, *args, &blk)
27
- @stack.unshift [middleware, args, blk]
28
- end
29
-
30
- def load(middleware)
31
- case middleware
32
- when String
33
- Object.const_get(middleware)
34
- else
35
- middleware
36
- end
37
- end
38
-
39
- def load_default_stack
40
- @default_stack_loaded ||= begin
41
- application.load!
42
- #use TzispaEnv, app
43
- end
44
- end
45
-
46
-
47
- end
48
- end
data/lib/tzispa/routes.rb DELETED
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
- require 'http_router'
5
- require 'tzispa/utils/string'
6
- require 'tzispa/controller/http_error'
7
-
8
-
9
- module Tzispa
10
-
11
- class Routes
12
-
13
- using Tzispa::Utils
14
-
15
- CONTROLLERS_BASE = 'Tzispa::Controller'
16
-
17
- attr_reader :router, :map_path
18
-
19
- def initialize(app, root=nil)
20
- @router = HttpRouter.new
21
- @app = app
22
- @router.default Tzispa::Controller::HttpError.new(app, :error_404)
23
- @map_path = root unless root=='/'
24
- end
25
-
26
- def path(path_id, params={})
27
- "#{@map_path}#{@router.path path_id, params}"
28
- end
29
-
30
- def routing(route_id, path, controller, methods: nil, matching: nil)
31
- spec_control, callmethod = controller.to_s.split(':')
32
- mpath = spec_control.split('#')
33
- req_controller = mpath.pop
34
- controller = req_controller.camelize
35
- if mpath.count > 1
36
- controller_module = mpath.collect!{ |w| w.capitalize }.join('::')
37
- require_relative "./controller/#{req_controller}"
38
- else
39
- controller_module = CONTROLLERS_BASE
40
- require "tzispa/controller/#{req_controller}"
41
- end
42
- @router.add(path).tap { |rule|
43
- rule.to "#{controller_module}::#{controller}".constantize.new(@app, callmethod)
44
- rule.name = route_id
45
- rule.add_request_method(methods) if methods
46
- rule.add_match_with(matching) if matching
47
- }
48
- end
49
-
50
-
51
- def route_rig_index(path, controller: nil, methods: nil)
52
- routing :index, path, controller || 'layout:render!', methods: methods
53
- end
54
-
55
- def route_rig_api(path, controller: nil, methods:nil)
56
- routing :api, path, controller || 'api:dispatch!', methods: methods
57
- end
58
-
59
- def route_rig_signed_api(path, controller: nil, methods: nil)
60
- routing :sapi, path, controller || 'api:dispatch!', methods: methods
61
- end
62
-
63
- def route_rig_layout(layout, path, controller: nil, methods: nil)
64
- routing layout, path, controller || 'layout:render!', methods: methods, matching: {layout: layout.to_s}
65
- end
66
-
67
- end
68
-
69
- end