alfa 0.0.1.pre → 0.0.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. data/assets/css/960gs/960.css +653 -0
  2. data/assets/css/960gs/960_12_col.css +357 -0
  3. data/assets/css/960gs/960_12_col_rtl.css +357 -0
  4. data/assets/css/960gs/960_16_col.css +446 -0
  5. data/assets/css/960gs/960_16_col_rtl.css +446 -0
  6. data/assets/css/960gs/960_24_col.css +621 -0
  7. data/assets/css/960gs/960_24_col_rtl.css +621 -0
  8. data/assets/css/960gs/960_rtl.css +653 -0
  9. data/assets/css/960gs/demo.css +55 -0
  10. data/assets/css/960gs/min/960.css +1 -0
  11. data/assets/css/960gs/min/960_12_col.css +1 -0
  12. data/assets/css/960gs/min/960_12_col_rtl.css +1 -0
  13. data/assets/css/960gs/min/960_16_col.css +1 -0
  14. data/assets/css/960gs/min/960_16_col_rtl.css +1 -0
  15. data/assets/css/960gs/min/960_24_col.css +1 -0
  16. data/assets/css/960gs/min/960_24_col_rtl.css +1 -0
  17. data/assets/css/960gs/min/960_rtl.css +1 -0
  18. data/assets/css/960gs/min/reset.css +1 -0
  19. data/assets/css/960gs/min/reset_rtl.css +1 -0
  20. data/assets/css/960gs/min/text.css +1 -0
  21. data/assets/css/960gs/min/text_rtl.css +1 -0
  22. data/assets/css/960gs/reset.css +211 -0
  23. data/assets/css/960gs/reset_rtl.css +211 -0
  24. data/assets/css/960gs/text.css +86 -0
  25. data/assets/css/960gs/text_rtl.css +86 -0
  26. data/assets/js/jquery/jquery-1.3.2.js +4376 -0
  27. data/assets/js/jquery/jquery-1.3.2.min.js +19 -0
  28. data/assets/js/jquery/jquery-1.4.2.js +6240 -0
  29. data/assets/js/jquery/jquery-1.4.2.min.js +154 -0
  30. data/assets/js/jquery/jquery-1.4.4.js +7179 -0
  31. data/assets/js/jquery/jquery-1.4.4.min.js +167 -0
  32. data/assets/js/jquery/jquery-1.8.2.js +9440 -0
  33. data/assets/js/jquery/jquery-1.8.2.min.js +2 -0
  34. data/assets/js/jquery/jquery-latest.js +2 -0
  35. data/assets/js/jquery/plugins/corner.js +178 -0
  36. data/assets/js/jquery/plugins/corner_12x.js +503 -0
  37. data/assets/js/jquery/plugins/datepick/calendar-green.gif +0 -0
  38. data/assets/js/jquery/plugins/datepick/calendar.gif +0 -0
  39. data/assets/js/jquery/plugins/datepick/datepickBasics.html +34 -0
  40. data/assets/js/jquery/plugins/datepick/flora.datepick.css +221 -0
  41. data/assets/js/jquery/plugins/datepick/humanity.datepick.css +192 -0
  42. data/assets/js/jquery/plugins/datepick/jquery.datepick-ar.js +27 -0
  43. data/assets/js/jquery/plugins/datepick/jquery.datepick-az.js +26 -0
  44. data/assets/js/jquery/plugins/datepick/jquery.datepick-bg.js +26 -0
  45. data/assets/js/jquery/plugins/datepick/jquery.datepick-ca.js +26 -0
  46. data/assets/js/jquery/plugins/datepick/jquery.datepick-cs.js +26 -0
  47. data/assets/js/jquery/plugins/datepick/jquery.datepick-da.js +26 -0
  48. data/assets/js/jquery/plugins/datepick/jquery.datepick-de.js +26 -0
  49. data/assets/js/jquery/plugins/datepick/jquery.datepick-el.js +26 -0
  50. data/assets/js/jquery/plugins/datepick/jquery.datepick-eo.js +26 -0
  51. data/assets/js/jquery/plugins/datepick/jquery.datepick-es.js +26 -0
  52. data/assets/js/jquery/plugins/datepick/jquery.datepick-et.js +26 -0
  53. data/assets/js/jquery/plugins/datepick/jquery.datepick-fa.js +26 -0
  54. data/assets/js/jquery/plugins/datepick/jquery.datepick-fi.js +26 -0
  55. data/assets/js/jquery/plugins/datepick/jquery.datepick-fr.js +26 -0
  56. data/assets/js/jquery/plugins/datepick/jquery.datepick-he.js +26 -0
  57. data/assets/js/jquery/plugins/datepick/jquery.datepick-hr.js +26 -0
  58. data/assets/js/jquery/plugins/datepick/jquery.datepick-hu.js +26 -0
  59. data/assets/js/jquery/plugins/datepick/jquery.datepick-hy.js +26 -0
  60. data/assets/js/jquery/plugins/datepick/jquery.datepick-id.js +26 -0
  61. data/assets/js/jquery/plugins/datepick/jquery.datepick-is.js +26 -0
  62. data/assets/js/jquery/plugins/datepick/jquery.datepick-it.js +26 -0
  63. data/assets/js/jquery/plugins/datepick/jquery.datepick-ja.js +26 -0
  64. data/assets/js/jquery/plugins/datepick/jquery.datepick-ko.js +26 -0
  65. data/assets/js/jquery/plugins/datepick/jquery.datepick-lt.js +26 -0
  66. data/assets/js/jquery/plugins/datepick/jquery.datepick-lv.js +26 -0
  67. data/assets/js/jquery/plugins/datepick/jquery.datepick-ms.js +26 -0
  68. data/assets/js/jquery/plugins/datepick/jquery.datepick-nl.js +26 -0
  69. data/assets/js/jquery/plugins/datepick/jquery.datepick-no.js +26 -0
  70. data/assets/js/jquery/plugins/datepick/jquery.datepick-pl.js +26 -0
  71. data/assets/js/jquery/plugins/datepick/jquery.datepick-pt-BR.js +26 -0
  72. data/assets/js/jquery/plugins/datepick/jquery.datepick-ro.js +26 -0
  73. data/assets/js/jquery/plugins/datepick/jquery.datepick-ru.js +26 -0
  74. data/assets/js/jquery/plugins/datepick/jquery.datepick-sk.js +26 -0
  75. data/assets/js/jquery/plugins/datepick/jquery.datepick-sl.js +27 -0
  76. data/assets/js/jquery/plugins/datepick/jquery.datepick-sq.js +26 -0
  77. data/assets/js/jquery/plugins/datepick/jquery.datepick-sr-SR.js +25 -0
  78. data/assets/js/jquery/plugins/datepick/jquery.datepick-sr.js +25 -0
  79. data/assets/js/jquery/plugins/datepick/jquery.datepick-sv.js +26 -0
  80. data/assets/js/jquery/plugins/datepick/jquery.datepick-th.js +26 -0
  81. data/assets/js/jquery/plugins/datepick/jquery.datepick-tr.js +26 -0
  82. data/assets/js/jquery/plugins/datepick/jquery.datepick-uk.js +26 -0
  83. data/assets/js/jquery/plugins/datepick/jquery.datepick-validation.js +141 -0
  84. data/assets/js/jquery/plugins/datepick/jquery.datepick-validation.min.js +8 -0
  85. data/assets/js/jquery/plugins/datepick/jquery.datepick-validation.pack.js +8 -0
  86. data/assets/js/jquery/plugins/datepick/jquery.datepick-zh-CN.js +26 -0
  87. data/assets/js/jquery/plugins/datepick/jquery.datepick-zh-TW.js +26 -0
  88. data/assets/js/jquery/plugins/datepick/jquery.datepick.css +216 -0
  89. data/assets/js/jquery/plugins/datepick/jquery.datepick.ent +76 -0
  90. data/assets/js/jquery/plugins/datepick/jquery.datepick.js +1974 -0
  91. data/assets/js/jquery/plugins/datepick/jquery.datepick.min.js +8 -0
  92. data/assets/js/jquery/plugins/datepick/jquery.datepick.pack.js +8 -0
  93. data/assets/js/jquery/plugins/datepick/redmond.datepick.css +204 -0
  94. data/assets/js/jquery/plugins/datepick/smoothness.datepick.css +205 -0
  95. data/assets/js/jquery/plugins/fancybox/blank.gif +0 -0
  96. data/assets/js/jquery/plugins/fancybox/fancy_close.png +0 -0
  97. data/assets/js/jquery/plugins/fancybox/fancy_loading.png +0 -0
  98. data/assets/js/jquery/plugins/fancybox/fancy_nav_left.png +0 -0
  99. data/assets/js/jquery/plugins/fancybox/fancy_nav_right.png +0 -0
  100. data/assets/js/jquery/plugins/fancybox/fancy_shadow_e.png +0 -0
  101. data/assets/js/jquery/plugins/fancybox/fancy_shadow_n.png +0 -0
  102. data/assets/js/jquery/plugins/fancybox/fancy_shadow_ne.png +0 -0
  103. data/assets/js/jquery/plugins/fancybox/fancy_shadow_nw.png +0 -0
  104. data/assets/js/jquery/plugins/fancybox/fancy_shadow_s.png +0 -0
  105. data/assets/js/jquery/plugins/fancybox/fancy_shadow_se.png +0 -0
  106. data/assets/js/jquery/plugins/fancybox/fancy_shadow_sw.png +0 -0
  107. data/assets/js/jquery/plugins/fancybox/fancy_shadow_w.png +0 -0
  108. data/assets/js/jquery/plugins/fancybox/fancy_title_left.png +0 -0
  109. data/assets/js/jquery/plugins/fancybox/fancy_title_main.png +0 -0
  110. data/assets/js/jquery/plugins/fancybox/fancy_title_over.png +0 -0
  111. data/assets/js/jquery/plugins/fancybox/fancy_title_right.png +0 -0
  112. data/assets/js/jquery/plugins/fancybox/fancybox-x.png +0 -0
  113. data/assets/js/jquery/plugins/fancybox/fancybox-y.png +0 -0
  114. data/assets/js/jquery/plugins/fancybox/fancybox.png +0 -0
  115. data/assets/js/jquery/plugins/fancybox/jquery.easing-1.3.pack.js +72 -0
  116. data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.2.css +359 -0
  117. data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.2.js +1136 -0
  118. data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.2.pack.js +46 -0
  119. data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.4.css +359 -0
  120. data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.4.js +1156 -0
  121. data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
  122. data/assets/js/jquery/plugins/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
  123. data/assets/js/jquery/plugins/jquery.cookie.js +96 -0
  124. data/assets/js/jquery/plugins/jquery.easing.1.3.js +205 -0
  125. data/assets/js/jquery/plugins/jquery.flash.js +288 -0
  126. data/assets/js/jquery/plugins/jquery.flash.min.js +1 -0
  127. data/assets/js/jquery/plugins/jquery.ifixpng.js +137 -0
  128. data/assets/js/jquery/plugins/jquery.mousewheel.js +84 -0
  129. data/assets/js/jquery/plugins/jquery.mousewheel.min.js +12 -0
  130. data/assets/js/jquery/plugins/jquery.numberformatter-1.2.2.js +486 -0
  131. data/assets/js/jquery/plugins/jquery.sifr.js +224 -0
  132. data/assets/js/jquery/plugins/jquery.sifr.min.js +1 -0
  133. data/assets/js/jquery/plugins/jquery.swfobject.js +1 -0
  134. data/assets/js/jquery/plugins/jquery.timers-1.1.2.js +147 -0
  135. data/assets/js/jquery/plugins/simplegallery.js +167 -0
  136. data/assets/js/jquery/ui/external/jquery.bgiframe-2.1.2.js +39 -0
  137. data/assets/js/jquery/ui/external/jquery.cookie.js +89 -0
  138. data/assets/js/jquery/ui/external/jquery.metadata.js +122 -0
  139. data/assets/js/jquery/ui/external/qunit.css +153 -0
  140. data/assets/js/jquery/ui/external/qunit.js +1261 -0
  141. data/assets/js/jquery/ui/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  142. data/assets/js/jquery/ui/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  143. data/assets/js/jquery/ui/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  144. data/assets/js/jquery/ui/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  145. data/assets/js/jquery/ui/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  146. data/assets/js/jquery/ui/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  147. data/assets/js/jquery/ui/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  148. data/assets/js/jquery/ui/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  149. data/assets/js/jquery/ui/images/ui-icons_222222_256x240.png +0 -0
  150. data/assets/js/jquery/ui/images/ui-icons_2e83ff_256x240.png +0 -0
  151. data/assets/js/jquery/ui/images/ui-icons_454545_256x240.png +0 -0
  152. data/assets/js/jquery/ui/images/ui-icons_888888_256x240.png +0 -0
  153. data/assets/js/jquery/ui/images/ui-icons_cd0a0a_256x240.png +0 -0
  154. data/assets/js/jquery/ui/jquery-ui-latest.min.js +778 -0
  155. data/assets/js/jquery/ui/themes/base/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  156. data/assets/js/jquery/ui/themes/base/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  157. data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  158. data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  159. data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  160. data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  161. data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  162. data/assets/js/jquery/ui/themes/base/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  163. data/assets/js/jquery/ui/themes/base/images/ui-icons_222222_256x240.png +0 -0
  164. data/assets/js/jquery/ui/themes/base/images/ui-icons_2e83ff_256x240.png +0 -0
  165. data/assets/js/jquery/ui/themes/base/images/ui-icons_454545_256x240.png +0 -0
  166. data/assets/js/jquery/ui/themes/base/images/ui-icons_888888_256x240.png +0 -0
  167. data/assets/js/jquery/ui/themes/base/images/ui-icons_cd0a0a_256x240.png +0 -0
  168. data/assets/js/jquery/ui/themes/base/jquery.ui.accordion.css +19 -0
  169. data/assets/js/jquery/ui/themes/base/jquery.ui.all.css +11 -0
  170. data/assets/js/jquery/ui/themes/base/jquery.ui.autocomplete.css +53 -0
  171. data/assets/js/jquery/ui/themes/base/jquery.ui.base.css +11 -0
  172. data/assets/js/jquery/ui/themes/base/jquery.ui.button.css +38 -0
  173. data/assets/js/jquery/ui/themes/base/jquery.ui.core.css +41 -0
  174. data/assets/js/jquery/ui/themes/base/jquery.ui.datepicker.css +68 -0
  175. data/assets/js/jquery/ui/themes/base/jquery.ui.dialog.css +21 -0
  176. data/assets/js/jquery/ui/themes/base/jquery.ui.progressbar.css +11 -0
  177. data/assets/js/jquery/ui/themes/base/jquery.ui.resizable.css +20 -0
  178. data/assets/js/jquery/ui/themes/base/jquery.ui.selectable.css +10 -0
  179. data/assets/js/jquery/ui/themes/base/jquery.ui.slider.css +24 -0
  180. data/assets/js/jquery/ui/themes/base/jquery.ui.tabs.css +18 -0
  181. data/assets/js/jquery/ui/themes/base/jquery.ui.theme.css +252 -0
  182. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  183. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  184. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  185. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  186. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  187. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  188. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  189. data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  190. data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_222222_256x240.png +0 -0
  191. data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  192. data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_454545_256x240.png +0 -0
  193. data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_888888_256x240.png +0 -0
  194. data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  195. data/assets/js/jquery/ui/themes/smoothness/jquery-ui-1.8.6.custom.css +572 -0
  196. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.accordion.css +19 -0
  197. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.all.css +11 -0
  198. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.autocomplete.css +53 -0
  199. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.base.css +11 -0
  200. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.button.css +38 -0
  201. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.core.css +41 -0
  202. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.datepicker.css +68 -0
  203. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.dialog.css +21 -0
  204. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.progressbar.css +11 -0
  205. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.resizable.css +20 -0
  206. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.selectable.css +10 -0
  207. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.slider.css +24 -0
  208. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.tabs.css +18 -0
  209. data/assets/js/jquery/ui/themes/smoothness/jquery.ui.theme.css +254 -0
  210. data/bin/alfa +15 -0
  211. data/lib/alfa/application.rb +36 -0
  212. data/lib/alfa/cli_application.rb +11 -3
  213. data/lib/alfa/commands/new.rb +4 -0
  214. data/lib/alfa/config.rb +11 -0
  215. data/lib/alfa/controller.rb +1 -1
  216. data/lib/alfa/database/mysql.rb +60 -8
  217. data/lib/alfa/database.rb +2 -1
  218. data/lib/alfa/logger.rb +38 -0
  219. data/lib/alfa/models/base.rb +1 -1
  220. data/lib/alfa/models/base_sql.rb +1 -1
  221. data/lib/alfa/models/dummy.rb +1 -1
  222. data/lib/alfa/models/mysql.rb +36 -26
  223. data/lib/alfa/models.rb +1 -1
  224. data/lib/alfa/query_logger.rb +29 -0
  225. data/lib/alfa/router.rb +155 -0
  226. data/lib/alfa/support.rb +58 -2
  227. data/lib/alfa/tfile.rb +97 -0
  228. data/lib/alfa/web_application.rb +106 -85
  229. data/lib/alfa.rb +1 -1
  230. data/lib/ruty/bugfix.rb +21 -0
  231. data/lib/ruty/tags/resources.rb +45 -2
  232. data/lib/ruty/upgrade.rb +61 -0
  233. data/test/data/test_router/config/routes.rb +4 -0
  234. data/test/test_alfa.rb +1 -52
  235. data/test/test_router.rb +132 -0
  236. data/test/test_support.rb +26 -0
  237. data/test/test_tfile.rb +186 -0
  238. metadata +259 -100
@@ -1,55 +1,107 @@
1
1
  require 'alfa/support'
2
2
  require 'mysql2'
3
+ require 'alfa/models/mysql'
4
+ require 'alfa/query_logger'
5
+ require 'yaml'
3
6
 
4
7
  module Alfa
5
8
  module Database
6
9
  class MySQL
7
10
  include Alfa::ClassInheritance
8
- inheritable_attributes :host, :port, :user, :password, :dbname, :client
11
+ inheritable_attributes :host, :port, :user, :password, :dbname, :client, :config, :schema_path, :encondig
9
12
  @host = nil
10
13
  @port = 3306
11
14
  @user = nil
12
15
  @password = nil
13
16
  @dbname = nil
14
17
  @client = nil
18
+ @config = nil
19
+ @schema_path = nil
20
+ @encoding = nil
21
+
22
+ def self.load_schema path
23
+ @schema_path = path
24
+ data = YAML::load File.open(File.join(path, 'schema.yml'))
25
+ data.symbolize_keys!
26
+ @encoding = data[:encoding] if data[:encoding]
27
+ raise "Unacceptible engine in #{path}/schema.yml, expected to be mysql of mysql2" unless ['mysql', 'mysql2'].include? data[:engine]
28
+ Dir[File.join(path, 'models/*.rb')].each do |file|
29
+ require file
30
+ Kernel::const_get(Alfa::Support.capitalize_name(File.basename(file, '.rb'))).register_database self
31
+ end
32
+
33
+ end
34
+
35
+ def self.load_config file
36
+ @config = file
37
+ data = YAML::load File.open(file)
38
+ data.symbolize_keys!
39
+ @host = data[:host] if data[:host]
40
+ @port = data[:port] if data[:port]
41
+ @user = data[:user] if data[:user]
42
+ @password = data[:password] if data[:password]
43
+ @dbname = data[:dbname] if data[:dbname]
44
+ end
15
45
 
16
46
  def self.check_params
17
47
  raise ":host must be defined for #{self.to_s}" unless @host
18
48
  raise ":user must be defined for #{self.to_s}" unless @user
19
49
  raise ":password must be defined for #{self.to_s}" unless @password
20
50
  raise ":dbname must be defined for #{self.to_s}" unless @dbname
51
+ raise ":encoding must be defined for #{self.to_s}" unless @encoding
21
52
  end
22
53
 
23
54
  def self.query query
55
+ self.check_client
24
56
  begin
25
- self.client.query(query)
57
+ Alfa::QueryLogger.log query, self do
58
+ @client.query(query)
59
+ end
26
60
  rescue Mysql2::Error => e
27
61
  raise "#{e.message} (query: \"#{query}\", error number: #{e.error_number}, sql state: #{e.sql_state})"
28
62
  end
29
63
  end
30
64
 
31
- def self.client
65
+ def self.check_client
32
66
  unless @client
33
67
  self.check_params
34
68
  @client = Mysql2::Client.new(:host=>@host, :username=>@user)
35
69
  @client.query_options.merge!(:symbolize_keys => true, :as => :hash, :database_timezone => :utc, :application_timezone => :utc)
36
- @client.query "SET NAMES utf8"
37
- @client.query "USE #{@dbname}"
70
+ Alfa::QueryLogger.log "SET NAMES utf8", self do
71
+ @client.query "SET NAMES " + @encoding
72
+ end
73
+ Alfa::QueryLogger.log "USE `#@dbname`", self do
74
+ @client.query "USE `#@dbname`"
75
+ end
38
76
  end
39
- @client
40
77
  end
41
78
 
42
79
  def self.transaction &block
80
+ self.check_client
43
81
  begin
44
82
  self.query "START TRANSACTION"
45
83
  yield
46
- rescue
84
+ rescue StandardError => e
47
85
  self.query "ROLLBACK"
86
+ raise e
48
87
  else
49
88
  self.query "COMMIT"
50
89
  end
51
90
  end
52
91
 
92
+ def self.escape arg
93
+ case arg.class
94
+ when Numeric
95
+ arg.to_s
96
+ when Array
97
+ arg.map {|a|
98
+ self.escape(a).to_s
99
+ }.join(',')
100
+ else
101
+ client.escape arg.to_s
102
+ end
103
+ end
104
+
53
105
  end
54
106
  end
55
- end
107
+ end
data/lib/alfa/database.rb CHANGED
@@ -1 +1,2 @@
1
- require 'alfa/database/mysql'
1
+ #require 'alfa/database/mysql'
2
+ require 'sequel'
@@ -0,0 +1,38 @@
1
+ require 'logger'
2
+
3
+ module Alfa
4
+ class Logger < ::Logger
5
+
6
+ def initialize(logdev, shift_age = 0, shift_size = 1048576)
7
+ super
8
+ @formatter = Formatter.new
9
+ end
10
+
11
+ def portion(&block)
12
+ io = VirtualIO.new
13
+ l = ::Logger.new(io)
14
+ l.formatter = @formatter
15
+ yield(l)
16
+ self << io.join
17
+ l = nil
18
+ io = nil
19
+ end
20
+
21
+ private
22
+
23
+ class VirtualIO < ::Array
24
+ def write(message)
25
+ self.push message
26
+ end
27
+
28
+ def close
29
+ end
30
+ end
31
+
32
+ class Formatter < ::Logger::Formatter
33
+ def call(severity, time, progname, msg)
34
+ msg2str("#{msg}\n")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -4,4 +4,4 @@ module Alfa
4
4
 
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -6,4 +6,4 @@ module Alfa
6
6
 
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -4,4 +4,4 @@ module Alfa
4
4
 
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -1,5 +1,4 @@
1
1
  require 'alfa/support'
2
- require 'alfa/database/mysql'
3
2
  require 'alfa/models/base_sql'
4
3
 
5
4
  module Alfa
@@ -7,46 +6,57 @@ module Alfa
7
6
  class MySQL < Alfa::Models::BaseSQL
8
7
  include Alfa::ClassInheritance
9
8
  inheritable_attributes :connection, :table
9
+
10
10
  @connection = nil
11
11
  @table = nil
12
12
  @pk = :id
13
13
 
14
- def self.register_database database
15
- raise 'Expected database to be instance of Alfa::Database::MySQL' unless database.ancestors.include? Alfa::Database::MySQL
16
- @connection = database
17
- end
14
+ class << self
18
15
 
19
- #@return Array || nil
20
- def self.all
21
- @connection.query("SELECT * FROM `#{self.table}`")
22
- end
16
+ def register_database database
17
+ raise 'Expected database to be instance of Alfa::Database::MySQL' unless database.ancestors.include? Alfa::Database::MySQL
18
+ @connection = database
19
+ end
23
20
 
24
- def self.find filter = {}
21
+ #@return Array || nil
22
+ def all
23
+ @connection.query("SELECT * FROM `#{self.table}`")
24
+ end
25
25
 
26
- end
26
+ def find filter = {}
27
27
 
28
- def self.find_first filter = {}
29
- end
28
+ end
30
29
 
31
- def self.count filter = {}
32
- end
30
+ def find_first filter = {}
31
+ end
33
32
 
34
- def self.exists? pk
35
- end
33
+ def count filter = {}
34
+ end
36
35
 
37
- def self.create data = {}
38
- end
36
+ def exists? pk
37
+ end
39
38
 
40
- def self.delete pk
41
- end
39
+ def create data = {}
40
+ #data.symbolize_keys!
41
+ @connection.query("INSERT INTO `#{self.table}` SET #{self.prepare_set_string(data)}")
42
+ end
42
43
 
43
- def self.update data = {}
44
- end
44
+ def delete pk
45
+ end
46
+
47
+ def update data = {}
48
+ end
49
+
50
+ def table
51
+ @table.to_s
52
+ end
53
+
54
+ def prepare_set_string data = {}
55
+ data.map{|field, value| "`#{@connection.escape(field)}`='#{@connection.escape(value)}'"}.join(', ')
56
+ end
45
57
 
46
- def self.table
47
- @table.to_s
48
58
  end
49
59
 
50
60
  end
51
61
  end
52
- end
62
+ end
data/lib/alfa/models.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'alfa/models/mysql'
2
- require 'alfa/models/dummy'
2
+ require 'alfa/models/dummy'
@@ -0,0 +1,29 @@
1
+ module Alfa
2
+ class QueryLogger
3
+ @logs = []
4
+ @num = 0
5
+ class << self
6
+ def log query, instance = nil, &block
7
+ @num += 1
8
+ if block_given?
9
+ log = {:num => @num, :query => query, :instance => instance, :status => :started, :error => nil, :logger_hash => self.hash}
10
+ @logs << log
11
+ begin
12
+ result = yield
13
+ rescue StandardError => e
14
+ log[:status] = :fail
15
+ log[:error] = e.message
16
+ raise e
17
+ end
18
+ log[:status] = :done
19
+ return result
20
+ else
21
+ @logs << {:num => @num, :query => query, :instance => instance, :status => :flat, :logger_hash => self.hash}
22
+ end
23
+ end
24
+ def logs
25
+ @logs
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,155 @@
1
+ module Alfa
2
+ class Router
3
+
4
+ # initialize class variables
5
+ @routes = []
6
+ @cursor = @routes
7
+ @cursors_stack = []
8
+ @mounts = []
9
+ @apps_dir = nil
10
+
11
+ def self.call &block
12
+ end
13
+
14
+ def self.set_apps_dir dir
15
+ @apps_dir = dir
16
+ end
17
+
18
+
19
+ def self.context options = {}, &block
20
+ new_routes_container = []
21
+ new_cursor = new_routes_container
22
+ if options.has_key?(:app)
23
+ app = @mounts.find {|item| item[:app] == options[:app]}
24
+ options[:app] = app
25
+ end
26
+ @cursor << {:context => options, :routes => new_routes_container}
27
+ @cursors_stack.push @cursor
28
+ @cursor = new_cursor
29
+ yield
30
+ @cursor = @cursors_stack.pop
31
+ end
32
+
33
+
34
+ def self.reset
35
+ @routes = []
36
+ end
37
+
38
+ # Set routes
39
+ # Example:
40
+ # WebApplication.Router.draw do
41
+ # mount '/admin/', :admin
42
+ # route '/rss.xml', 'frontend/feeds#rss'
43
+ # route '/atom.xml', 'frontend/feeds#atom'
44
+ # mount '/', :frontend
45
+ # subdomain :forum do
46
+ # mount '/', :forum
47
+ # end
48
+ # end
49
+ def self.draw &block
50
+ route '/~assets/:path**', :type => :asset if @cursors_stack.empty?
51
+ class_eval &block
52
+ end
53
+
54
+ # Set rules in subdomain context
55
+ def self.subdomain &block
56
+ end
57
+
58
+ # Mount application to path
59
+ # Examples:
60
+ # all requests to url site.com/admin/ and nested (site.com/admin/*) will be sent to application 'backend' (/apps/backend)
61
+ # mount '/admin/', :admin
62
+ # all requests to site.com/ and nested (site.com/*) will be sent to application 'frontend' (/apps/frontend)
63
+ # mount '/', :frontend
64
+ def self.mount path, app, options = {}
65
+ @mounts << {:path => path, :app => app, :options => options}
66
+ if @apps_dir
67
+ self.context :app => app do
68
+ require File.join(@apps_dir, app.to_s, 'routes')
69
+ end
70
+ end
71
+ end
72
+
73
+ # Sets route rule
74
+ def self.route rule, options = {}
75
+ @cursor << {:rule => rule, :options => options}
76
+ #puts "set rule '#{rule}', routes = #{@routes}"
77
+ end
78
+
79
+ # @todo write tests for this method
80
+ def self.app_match? path, url
81
+ path_segments = path.split('/').reject(&:empty?)
82
+ url_segments = url.split('/').reject(&:empty?)
83
+ path_segments.zip(url_segments).reduce(true) {|res, pare| res && pare[0] == pare[1]}
84
+ end
85
+
86
+
87
+ def self.route_match? rule, url
88
+ #bputs rule
89
+ if rule.is_a? String
90
+ rule_trail_slash = rule[-1] == '/'
91
+ url_trail_slash = url[-1] == '/'
92
+ rule_segments = rule.split('/').reject(&:empty?) # @todo optimize (one split per server session instead of split per method call)
93
+ url_segments = url.split('/').reject(&:empty?) # @todo optimize (one split per server session instead of split per method call)
94
+ if rule_segments.first == '~assets' && url_segments.first == '~assets'
95
+ path = url_segments[1..-1].join('/')
96
+ if File.file?(File.expand_path('../../../assets/'+path, __FILE__))
97
+ return true, {path: path, type: :asset}
98
+ else
99
+ return false, {}
100
+ end
101
+ end
102
+ rule_segments += [nil]*(url_segments.size - rule_segments.size) if url_segments.size > rule_segments.size
103
+ pares = {}
104
+ skip_flag = false
105
+ fail_flag = false
106
+ rule_segments.zip(url_segments).each do |rule_segment, url_segment|
107
+ skip_flag = true if rule_segment == '**'
108
+ if rule_segment =~ /^:[a-z]+\w*$/i && url_segment =~ /^[a-z0-9_]+$/
109
+ pares[rule_segment[1..-1].to_sym] = url_segment
110
+ elsif (rule_segment == url_segment) || (rule_segment == '*' && url_segment =~ /^[a-z0-9_]+$/) || (rule_segment == nil && skip_flag) || rule_segment == '**'
111
+ else
112
+ fail_flag = true
113
+ break
114
+ end
115
+ end
116
+ fail_flag = true if rule_trail_slash != url_trail_slash
117
+ return !fail_flag, pares
118
+ elsif rule.is_a? Regexp
119
+ match = rule.match url
120
+ if match
121
+ pares = Hash[match.names.map(&:to_sym).zip(match.captures)]
122
+ return true, pares
123
+ else
124
+ return false, {}
125
+ end
126
+ end
127
+ end
128
+
129
+ # @param string url
130
+ # @return route, params
131
+ # route is route that given in routes.rb
132
+ # params is detected params
133
+ def self.find_route url
134
+ @routes.each do |route|
135
+ if route[:context].is_a? Hash # container
136
+ if self.app_match?(route[:context][:app][:path], url)
137
+ url = url[(route[:context][:app][:path].length-1)..-1]
138
+ route[:routes].each do |r|
139
+ is_success, params = self.route_match?(r[:rule], url)
140
+ r[:options][:app] = route[:context][:app][:app]
141
+ return r, params if is_success
142
+ end
143
+ raise Alfa::RouteException404
144
+ end
145
+ # else - ???
146
+ else
147
+ is_success, params = self.route_match?(route[:rule], url)
148
+ return route, params if is_success
149
+ end
150
+ end
151
+ raise Alfa::RouteException404
152
+ end
153
+
154
+ end
155
+ end
data/lib/alfa/support.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Alfa
2
2
 
3
- # thanks to John
3
+ # Thanks to John
4
4
  # http://railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/
5
5
  module ClassInheritance
6
6
  def self.included(base)
@@ -34,4 +34,60 @@ module Alfa
34
34
  end
35
35
  end
36
36
 
37
- end
37
+ end
38
+
39
+
40
+ class Module
41
+ def load_in_module_context file
42
+ module_eval file, file
43
+ end
44
+
45
+ def load_in_class_context file
46
+ class_eval file, file
47
+ end
48
+ end
49
+
50
+
51
+ class BasicObject
52
+ def load_in_instance_context file
53
+ instance_eval file, file
54
+ end
55
+ end
56
+
57
+ # Borrowed from active_support/core_ext/hash/keys.rb
58
+ class Hash
59
+ # Return a new hash with all keys converted to strings.
60
+ #
61
+ # { :name => 'Rob', :years => '28' }.stringify_keys
62
+ # #=> { "name" => "Rob", "years" => "28" }
63
+ def stringify_keys
64
+ dup.stringify_keys!
65
+ end
66
+
67
+ # Destructively convert all keys to strings. Same as
68
+ # +stringify_keys+, but modifies +self+.
69
+ def stringify_keys!
70
+ keys.each do |key|
71
+ self[key.to_s] = delete(key)
72
+ end
73
+ self
74
+ end
75
+
76
+ # Return a new hash with all keys converted to symbols, as long as
77
+ # they respond to +to_sym+.
78
+ #
79
+ # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
80
+ # #=> { :name => "Rob", :years => "28" }
81
+ def symbolize_keys
82
+ dup.symbolize_keys!
83
+ end
84
+
85
+ # Destructively convert all keys to symbols, as long as they respond
86
+ # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
87
+ def symbolize_keys!
88
+ keys.each do |key|
89
+ self[(key.to_sym rescue key) || key] = delete(key)
90
+ end
91
+ self
92
+ end
93
+ end
data/lib/alfa/tfile.rb ADDED
@@ -0,0 +1,97 @@
1
+ require 'alfa/support'
2
+
3
+ module Alfa
4
+ class TFile
5
+
6
+ class << self
7
+ attr_reader :project_root, :document_root
8
+ def project_root=(arg)
9
+ @project_root = File.expand_path(arg) + '/'
10
+ @document_root = @project_root + 'public/'
11
+ end
12
+ def document_root=(arg)
13
+ @document_root = File.expand_path(arg) + '/'
14
+ end
15
+ def allowed_options
16
+ @allowed_options ||= %w(absfile projfile url).map(&:to_sym)
17
+ end
18
+ def inherited(subclass)
19
+ subclass.instance_variable_set(:@project_root, instance_variable_get(:@project_root))
20
+ subclass.instance_variable_set(:@document_root, instance_variable_get(:@document_root))
21
+ end
22
+
23
+ end
24
+
25
+ attr_reader :absfile, :absdir, :basename, :dirname
26
+
27
+ def initialize options={}
28
+ (options.keys - self.class.allowed_options).each do |opt|
29
+ raise "unknown option #{opt}, expected one of: #{self.class.allowed_options.join(', ')}"
30
+ end
31
+ raise "only one of #{self.class.allowed_options.join(', ')} allowed" if options.length > 1
32
+ if options.has_key?(:absfile)
33
+ self.absfile= options[:absfile]
34
+ elsif options.has_key? :projfile
35
+ self.projfile= options[:projfile]
36
+ end
37
+ end
38
+
39
+ def absfile= arg
40
+ @absfile = arg
41
+ @basename = File.basename(arg)
42
+ @dirname = File.dirname(arg) + '/'
43
+ end
44
+
45
+ def projfile= arg
46
+ raise "Please set up #{self.class}.project_root before call #{__method__}" unless self.class.project_root
47
+ self.absfile= File.join(self.class.project_root, arg)
48
+ end
49
+
50
+ def basename= arg
51
+ @basename = arg
52
+ @absfile = File.join(@dirname, @basename)
53
+ end
54
+
55
+ def extname
56
+ File.extname(@basename)
57
+ end
58
+
59
+ def extname= arg
60
+ arg = '.' + arg unless arg =~ /^\./
61
+ self.basename= self.filename + arg
62
+ end
63
+
64
+ def filename
65
+ File.basename(@basename, File.extname(@basename))
66
+ end
67
+
68
+ def filename= arg
69
+ self.basename= arg + self.extname
70
+ end
71
+
72
+ def dirname= arg
73
+ @dirname = File.expand_path(arg) + '/'
74
+ @absfile = File.join(@dirname, @basename)
75
+ end
76
+
77
+ def url
78
+ if self.absfile[0, self.class.document_root.length] == self.class.document_root
79
+ self.absfile[(self.class.document_root.length-1)..-1]
80
+ end
81
+ end
82
+
83
+ def url= arg
84
+ raise "Please set up #{self.class}.document_root before call #{__method__}" unless self.class.document_root
85
+ self.absfile= File.join(self.class.document_root, arg)
86
+ end
87
+
88
+ def to_str
89
+ self.absfile
90
+ end
91
+
92
+ def to_s
93
+ self.to_str
94
+ end
95
+
96
+ end
97
+ end