Pistos-ramaze 2009.04.08 → 2009.06.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. data/.gitignore +3 -0
  2. data/MANIFEST +37 -22
  3. data/{README.markdown → README.md} +5 -24
  4. data/Rakefile +33 -26
  5. data/benchmark/bench_templates/bench.rb +67 -0
  6. data/benchmark/bench_templates/view/large.erb +79 -0
  7. data/benchmark/bench_templates/view/large.haml +41 -0
  8. data/benchmark/bench_templates/view/large.xhtml +79 -0
  9. data/benchmark/bench_templates/view/small.erb +21 -0
  10. data/benchmark/bench_templates/view/small.haml +12 -0
  11. data/benchmark/bench_templates/view/small.xhtml +21 -0
  12. data/benchmark/run.rb +14 -21
  13. data/benchmark/suite/minimal.rb +3 -5
  14. data/benchmark/suite/no_informer.rb +0 -2
  15. data/benchmark/suite/no_sessions.rb +3 -4
  16. data/benchmark/suite/no_template.rb +1 -3
  17. data/benchmark/suite/simple.rb +1 -3
  18. data/benchmark/suite/template_erubis.rb +0 -2
  19. data/benchmark/suite/template_etanni.rb +8 -0
  20. data/benchmark/suite/template_ezamar.rb +1 -3
  21. data/benchmark/suite/template_haml.rb +0 -2
  22. data/benchmark/suite/template_liquid.rb +0 -2
  23. data/benchmark/suite/template_markaby.rb +0 -2
  24. data/benchmark/suite/template_nagoro.rb +1 -3
  25. data/benchmark/suite/template_redcloth.rb +0 -2
  26. data/benchmark/suite/template_tenjin.rb +0 -2
  27. data/bin/ramaze +11 -163
  28. data/doc/AUTHORS +15 -8
  29. data/doc/CHANGELOG +10094 -12262
  30. data/doc/meta/announcement.txt +93 -46
  31. data/doc/tutorial/todolist.html +22 -58
  32. data/doc/tutorial/todolist.txt +20 -39
  33. data/examples/app/auth/layout/{auth.nag → auth.xhtml} +0 -0
  34. data/examples/app/auth/view/{index.nag → index.xhtml} +0 -0
  35. data/examples/app/auth/view/{login.nag → login.xhtml} +0 -0
  36. data/examples/app/auth/view/{secret.nag → secret.xhtml} +0 -0
  37. data/examples/app/blog/app.rb +1 -1
  38. data/examples/app/blog/controller/comment.rb +1 -1
  39. data/examples/app/blog/controller/entry.rb +12 -3
  40. data/examples/app/blog/model/init.rb +5 -0
  41. data/examples/app/blog/model/tag.rb +2 -2
  42. data/examples/app/blog/view/entry/index.nag +3 -3
  43. data/examples/app/blog/view/feed.atom.nag +1 -1
  44. data/examples/app/blog/view/feed.rss.nag +1 -1
  45. data/examples/app/blog/view/index.nag +1 -1
  46. data/examples/app/blog/view/tag/index.nag +1 -1
  47. data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
  48. data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
  49. data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
  50. data/examples/app/localization/locale/de.yaml +5 -0
  51. data/examples/app/localization/locale/en.yaml +5 -0
  52. data/examples/app/localization/locale/ja.yaml +5 -0
  53. data/examples/app/localization/start.rb +33 -20
  54. data/examples/app/wikore/spec/wikore.rb +4 -6
  55. data/examples/app/wikore/src/controller.rb +9 -11
  56. data/examples/app/wikore/src/model.rb +7 -10
  57. data/examples/app/wikore/start.rb +1 -1
  58. data/examples/app/wikore/{template → view}/index.xhtml +0 -0
  59. data/examples/helpers/cache.rb +6 -4
  60. data/examples/misc/css.rb +6 -12
  61. data/examples/misc/rapp.rb +28 -17
  62. data/lib/proto/app.rb +14 -0
  63. data/lib/proto/config.ru +8 -5
  64. data/lib/proto/controller/init.rb +3 -3
  65. data/lib/proto/spec/main.rb +9 -11
  66. data/lib/proto/start.rb +6 -10
  67. data/lib/ramaze.rb +8 -9
  68. data/lib/ramaze/app.rb +4 -3
  69. data/lib/ramaze/cache/localmemcache.rb +2 -2
  70. data/lib/ramaze/cache/memcache.rb +26 -1
  71. data/lib/ramaze/cache/sequel.rb +24 -9
  72. data/lib/ramaze/contrib/addressable_route.rb +56 -0
  73. data/lib/ramaze/contrib/email.rb +2 -0
  74. data/lib/ramaze/contrib/facebook/facebook.rb +4 -4
  75. data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
  76. data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
  77. data/lib/ramaze/contrib/sequel/image.rb +9 -11
  78. data/lib/ramaze/contrib/sequel/relation.rb +17 -3
  79. data/lib/ramaze/controller.rb +26 -18
  80. data/lib/ramaze/gestalt.rb +4 -1
  81. data/lib/ramaze/helper.rb +1 -0
  82. data/lib/ramaze/helper/auth.rb +0 -5
  83. data/lib/ramaze/helper/cache.rb +65 -25
  84. data/lib/ramaze/helper/form.rb +14 -2
  85. data/lib/ramaze/helper/formatting.rb +3 -1
  86. data/lib/ramaze/helper/gestalt.rb +32 -0
  87. data/lib/ramaze/helper/identity.rb +3 -3
  88. data/lib/ramaze/helper/layout.rb +97 -0
  89. data/lib/ramaze/helper/link.rb +6 -25
  90. data/lib/ramaze/helper/localize.rb +13 -3
  91. data/lib/ramaze/helper/paginate.rb +4 -2
  92. data/lib/ramaze/helper/ultraviolet.rb +2 -0
  93. data/lib/ramaze/helper/user.rb +3 -3
  94. data/lib/ramaze/log/rotatinginformer.rb +10 -10
  95. data/lib/ramaze/request.rb +3 -5
  96. data/lib/ramaze/setup.rb +22 -9
  97. data/lib/ramaze/spec.rb +8 -12
  98. data/lib/ramaze/spec/bacon.rb +34 -0
  99. data/lib/ramaze/spec/helper/template_examples.rb +15 -22
  100. data/lib/ramaze/tool/bin.rb +340 -0
  101. data/lib/ramaze/tool/project_creator.rb +1 -1
  102. data/lib/ramaze/version.rb +1 -1
  103. data/lib/ramaze/view.rb +6 -11
  104. data/lib/ramaze/view/erubis.rb +2 -2
  105. data/lib/ramaze/view/ezamar.rb +2 -2
  106. data/lib/ramaze/view/gestalt.rb +14 -0
  107. data/lib/ramaze/view/haml.rb +2 -1
  108. data/lib/ramaze/view/liquid.rb +45 -11
  109. data/lib/ramaze/view/maruku.rb +2 -1
  110. data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
  111. data/lib/ramaze/view/sass.rb +1 -1
  112. data/lib/ramaze/view/tenjin.rb +7 -4
  113. data/lib/vendor/etag.rb +4 -2
  114. data/lib/vendor/route_exceptions.rb +9 -15
  115. data/ramaze.gemspec +56 -9
  116. data/spec/contrib/addressable_route.rb +30 -0
  117. data/spec/contrib/rest.rb +2 -2
  118. data/spec/examples/caching.rb +5 -7
  119. data/spec/examples/css.rb +3 -3
  120. data/spec/examples/element.rb +4 -3
  121. data/spec/examples/hello.rb +3 -3
  122. data/spec/examples/helpers/httpdigest.rb +44 -69
  123. data/spec/examples/linking.rb +3 -3
  124. data/spec/examples/simple.rb +3 -3
  125. data/spec/examples/templates/template_erubis.rb +8 -4
  126. data/spec/examples/templates/template_ezamar.rb +9 -4
  127. data/spec/examples/templates/template_haml.rb +8 -4
  128. data/spec/examples/templates/template_liquid.rb +8 -4
  129. data/spec/examples/templates/template_markaby.rb +9 -5
  130. data/spec/examples/templates/template_nagoro.rb +9 -5
  131. data/spec/examples/templates/template_redcloth.rb +8 -4
  132. data/spec/examples/templates/template_remarkably.rb +8 -4
  133. data/spec/examples/templates/template_tenjin.rb +8 -4
  134. data/spec/helper.rb +1 -2
  135. data/spec/ramaze/action/render.rb +4 -1
  136. data/spec/ramaze/app.rb +5 -2
  137. data/spec/ramaze/bin/ramaze.rb +96 -0
  138. data/spec/ramaze/cache/localmemcache.rb +1 -1
  139. data/spec/ramaze/cache/memcache.rb +7 -1
  140. data/spec/ramaze/cache/sequel.rb +1 -1
  141. data/spec/ramaze/controller/actionless_templates.rb +2 -2
  142. data/spec/ramaze/controller/lonely_mapping.rb +18 -0
  143. data/spec/ramaze/controller/mapping.rb +4 -15
  144. data/spec/ramaze/controller/provide_inheritance.rb +5 -2
  145. data/spec/ramaze/controller/resolve.rb +2 -2
  146. data/spec/ramaze/controller/subclass.rb +2 -2
  147. data/spec/ramaze/controller/template_resolving.rb +2 -2
  148. data/spec/ramaze/dispatcher/directory.rb +5 -2
  149. data/spec/ramaze/dispatcher/file.rb +28 -26
  150. data/spec/ramaze/error.rb +3 -3
  151. data/spec/ramaze/files.rb +5 -2
  152. data/spec/ramaze/gestalt.rb +26 -17
  153. data/spec/ramaze/helper/auth.rb +30 -41
  154. data/spec/ramaze/helper/bench.rb +6 -2
  155. data/spec/ramaze/helper/cache.rb +45 -5
  156. data/spec/ramaze/helper/flash.rb +11 -15
  157. data/spec/ramaze/helper/form.rb +6 -3
  158. data/spec/ramaze/helper/formatting.rb +4 -1
  159. data/spec/ramaze/helper/gestalt.rb +4 -1
  160. data/spec/ramaze/helper/gravatar.rb +4 -1
  161. data/spec/ramaze/helper/httpdigest.rb +51 -66
  162. data/spec/ramaze/helper/layout.rb +79 -0
  163. data/spec/ramaze/helper/layout/default.xhtml +5 -0
  164. data/spec/ramaze/helper/link.rb +33 -12
  165. data/spec/ramaze/helper/localize.rb +9 -4
  166. data/spec/ramaze/helper/maruku.rb +5 -2
  167. data/spec/ramaze/helper/pager.rb +2 -2
  168. data/spec/ramaze/helper/paginate.rb +5 -2
  169. data/spec/ramaze/helper/request_accessor.rb +5 -2
  170. data/spec/ramaze/helper/sequel_form.rb +7 -2
  171. data/spec/ramaze/helper/simple_captcha.rb +10 -14
  172. data/spec/ramaze/helper/stack.rb +32 -40
  173. data/spec/ramaze/helper/user.rb +19 -14
  174. data/spec/ramaze/helper/xhtml.rb +4 -1
  175. data/spec/ramaze/log/informer.rb +1 -1
  176. data/spec/ramaze/log/logging.rb +4 -1
  177. data/spec/ramaze/log/syslog.rb +6 -6
  178. data/spec/ramaze/params.rb +5 -6
  179. data/spec/ramaze/request.rb +16 -1
  180. data/spec/ramaze/session/memcache.rb +66 -0
  181. data/spec/ramaze/struct.rb +4 -1
  182. data/spec/ramaze/view.rb +2 -2
  183. data/spec/ramaze/view/erubis.rb +2 -2
  184. data/spec/ramaze/view/ezamar.rb +2 -2
  185. data/spec/ramaze/view/gestalt.rb +94 -0
  186. data/spec/ramaze/view/gestalt/external.ges +8 -0
  187. data/spec/ramaze/view/haml.rb +2 -2
  188. data/spec/ramaze/view/liquid.rb +2 -2
  189. data/spec/ramaze/view/nagoro.rb +2 -2
  190. data/spec/ramaze/view/redcloth.rb +2 -2
  191. data/spec/ramaze/view/remarkably.rb +2 -2
  192. data/spec/ramaze/view/sass.rb +2 -2
  193. data/spec/ramaze/view/tagz.rb +2 -2
  194. data/spec/ramaze/view/tenjin.rb +2 -2
  195. data/spec/snippets/array/put_within.rb +30 -25
  196. data/spec/snippets/binding/locals.rb +4 -1
  197. data/spec/snippets/numeric/filesize_format.rb +4 -1
  198. data/spec/snippets/numeric/time.rb +5 -2
  199. data/spec/snippets/object/__dir__.rb +4 -1
  200. data/spec/snippets/ordered_set.rb +4 -1
  201. data/spec/snippets/ramaze/acquire.rb +4 -1
  202. data/spec/snippets/ramaze/dictionary.rb +4 -1
  203. data/spec/snippets/ramaze/struct.rb +4 -1
  204. data/spec/snippets/string/camel_case.rb +4 -1
  205. data/spec/snippets/string/color.rb +4 -1
  206. data/spec/snippets/string/snake_case.rb +4 -1
  207. data/spec/snippets/string/unindent.rb +4 -1
  208. data/spec/snippets/thread/into.rb +4 -1
  209. data/tasks/bacon.rake +5 -3
  210. data/tasks/changelog.rake +3 -1
  211. data/tasks/{gem_installer.rake → gem_setup.rake} +45 -22
  212. data/tasks/release.rake +12 -27
  213. data/tasks/setup.rake +6 -0
  214. data/tasks/todo.rake +2 -4
  215. metadata +205 -31
  216. data/CHANGELOG +0 -16546
  217. data/benchmark/suite/template_builder.rb +0 -12
  218. data/doc/tutorial/todolist.mkd +0 -787
  219. data/examples/helpers/provide.rb +0 -23
  220. data/lib/proto/view/page.xhtml +0 -27
  221. data/lib/ramaze/snippets/divide.rb +0 -22
  222. data/lib/ramaze/snippets/kernel/constant.rb +0 -41
  223. data/lib/ramaze/snippets/object/acquire.rb +0 -37
  224. data/lib/ramaze/snippets/string/each.rb +0 -19
  225. data/spec/ramaze/helper/partial.rb +0 -40
  226. data/spec/snippets/kernel/constant.rb +0 -23
  227. data/tasks/install_dependencies.rake +0 -6
@@ -0,0 +1,14 @@
1
+ # This file contains your application, it requires dependencies and necessary
2
+ # parts of the application.
3
+ #
4
+ # It will be required from either `config.ru` or `start.rb`
5
+
6
+ require 'rubygems'
7
+ require 'ramaze'
8
+
9
+ # Make sure that Ramaze knows where you are
10
+ Ramaze.options.roots = [__DIR__]
11
+
12
+ # Initialize controllers and models
13
+ require __DIR__('model/init')
14
+ require __DIR__('controller/init')
@@ -8,10 +8,13 @@
8
8
  # Rack::Builder DSL to configure middleware and build up applications easily.
9
9
  #
10
10
  # rackup automatically figures out the environment it is run in, and runs your
11
- # application as FastCGI, CGI, or standalone with Mongrel or WEBrickall from
11
+ # application as FastCGI, CGI, or standalone with Mongrel or WEBrick -- all from
12
12
  # the same configuration.
13
+ #
14
+ # Do not set the adapter.handler in here, it will be ignored.
15
+ # You can choose the adapter like `ramaze start -s mongrel` or set it in the
16
+ # 'start.rb' and use `ruby start.rb` instead.
13
17
 
14
- cwd = File.dirname(__FILE__)
15
- require "#{cwd}/start"
16
- Ramaze.start(:started => true)
17
- run Innate
18
+ require ::File.expand_path('../app', __FILE__)
19
+ Ramaze.start(:root => __DIR__, :started => true)
20
+ run Ramaze
@@ -2,10 +2,10 @@
2
2
  # controllers
3
3
 
4
4
  class Controller < Ramaze::Controller
5
- layout 'default'
5
+ layout :default
6
6
  helper :xhtml
7
- engine :Nagoro
7
+ engine :Etanni
8
8
  end
9
9
 
10
10
  # Here go your requires for subclasses of Controller:
11
- require 'controller/main'
11
+ require __DIR__('main')
@@ -1,22 +1,20 @@
1
1
  require 'ramaze'
2
- require 'ramaze/spec'
2
+ require 'ramaze/spec/bacon'
3
3
 
4
- require __DIR__('../start')
4
+ require __DIR__('../app')
5
5
 
6
6
  describe MainController do
7
- behaves_like :mock
7
+ behaves_like :rack_test
8
8
 
9
9
  should 'show start page' do
10
- got = get('/')
11
- got.status.should == 200
12
- got['Content-Type'].should == 'text/html'
13
- got.body.should =~ /<h1>Welcome to Ramaze!<\/h1>/
10
+ get('/').status.should == 200
11
+ last_response['Content-Type'].should == 'text/html'
12
+ last_response.should =~ /<h1>Welcome to Ramaze!<\/h1>/
14
13
  end
15
14
 
16
15
  should 'show /notemplate' do
17
- got = get('/notemplate')
18
- got.status.should == 200
19
- got['Content-Type'].should == 'text/html'
20
- got.body.should =~ /there is no 'notemplate.xhtml' associated with this action/
16
+ get('/notemplate').status.should == 200
17
+ last_response['Content-Type'].should == 'text/html'
18
+ last_response.should =~ /there is no 'notemplate\.xhtml' associated with this action/
21
19
  end
22
20
  end
@@ -1,12 +1,8 @@
1
- require 'rubygems'
2
- require 'ramaze'
1
+ # Use this file directly like `ruby start.rb` if you don't want to use the
2
+ # `ramaze start` command.
3
+ # All application related things should go into `app.rb`, this file is simply
4
+ # for options related to running the application locally.
3
5
 
4
- # Add the directory this file resides in to the load path, so you can run the
5
- # app from any other working directory
6
- $LOAD_PATH.unshift(__DIR__)
6
+ require File.expand_path('app', File.dirname(__FILE__))
7
7
 
8
- # Initialize controllers and models
9
- require 'controller/init'
10
- require 'model/init'
11
-
12
- Ramaze.start(:adapter => :webrick, :port => 7000) if __FILE__ == $0
8
+ Ramaze.start(:adapter => :webrick, :port => 7000, :file => __FILE__)
@@ -62,25 +62,24 @@ module Ramaze
62
62
 
63
63
  middleware! :dev do |m|
64
64
  m.use Rack::Lint
65
- m.use Rack::CommonLogger
66
- m.use Ramaze::Reloader
65
+ m.use Rack::CommonLogger, Ramaze::Log
66
+ m.use Rack::ShowExceptions
67
67
  m.use Rack::ShowStatus
68
68
  m.use Rack::RouteExceptions
69
- m.use Rack::ShowExceptions
70
- m.use Rack::Head
71
- m.use Rack::ETag
72
69
  m.use Rack::ConditionalGet
70
+ m.use Rack::ETag
71
+ m.use Rack::Head
72
+ m.use Ramaze::Reloader
73
73
  m.run Ramaze::AppMap
74
74
  end
75
75
 
76
76
  middleware! :live do |m|
77
- m.use Rack::CommonLogger
77
+ m.use Rack::CommonLogger, Ramaze::Log
78
78
  m.use Rack::RouteExceptions
79
79
  m.use Rack::ShowStatus
80
- m.use Rack::ShowExceptions
81
- m.use Rack::Head
82
- m.use Rack::ETag
83
80
  m.use Rack::ConditionalGet
81
+ m.use Rack::ETag
82
+ m.use Rack::Head
84
83
  m.run Ramaze::AppMap
85
84
  end
86
85
  end
@@ -70,10 +70,10 @@ module Ramaze
70
70
 
71
71
  attr_reader :name, :location, :url_map, :options
72
72
 
73
- def initialize(name, location)
73
+ def initialize(name, location = nil)
74
74
  @name = name.to_sym
75
75
  @url_map = Innate::URLMap.new
76
- self.location = location
76
+ self.location = location if location
77
77
 
78
78
  APP_LIST[@name] = self
79
79
 
@@ -113,7 +113,8 @@ module Ramaze
113
113
  roots.map{|root| publics.map{|public| ::File.join(root, public) }}.flatten
114
114
  end
115
115
 
116
- def self.find_or_create(name, location = '/')
116
+ def self.find_or_create(name, location = nil)
117
+ location = '/' if location.nil? && name == :pristine
117
118
  self[name] || new(name, location)
118
119
  end
119
120
 
@@ -31,11 +31,11 @@ module Ramaze
31
31
 
32
32
  # Wipe out _all_ data in localmemcached, use with care.
33
33
  def cache_clear
34
- ::LocalMemCache.clear_namespace(@namespace)
34
+ @store.clear
35
35
  end
36
36
 
37
37
  def cache_delete(*args)
38
- super{|key| @store.delete(key.to_s) }
38
+ super{|key| @store.delete(key.to_s); nil }
39
39
  end
40
40
 
41
41
  # NOTE:
@@ -13,7 +13,20 @@ module Ramaze
13
13
  #
14
14
  # It is highly recommended to install memcache-client_extensions for
15
15
  # a bit of speedup and more functionality
16
+ #
17
+ # NOTE: There is a big issue with persisting sessions in memcache, not only
18
+ # can they be dropped at any time, essentially logging the user out
19
+ # without them noticing, but there is also a low limit to the maximum
20
+ # time-to-live. After 30 days, your session will be dropped, no
21
+ # matter what.
22
+ # Please remember that memcache is, first of all, a cache, not a
23
+ # persistence mechanism.
24
+ #
25
+ # NOTE: If you try to set a higher ttl than allowed, your stored key/value
26
+ # will be expired immediately.
16
27
  class MemCache
28
+ MAX_TTL = 2592000
29
+
17
30
  include Cache::API
18
31
 
19
32
  # +:multithread+: May be turned off at your own risk.
@@ -34,6 +47,7 @@ module Ramaze
34
47
  options = {:namespace => @namespace}.merge(OPTIONS)
35
48
  servers = options.delete(:servers)
36
49
  @store = ::MemCache.new(servers, options)
50
+ @warned = false
37
51
  end
38
52
 
39
53
  # Wipe out _all_ data in memcached, use with care.
@@ -46,7 +60,7 @@ module Ramaze
46
60
 
47
61
  #
48
62
  def cache_delete(*keys)
49
- super{|key| @store.delete(key) }
63
+ super{|key| @store.delete(key); nil }
50
64
  rescue ::MemCache::MemCacheError => e
51
65
  Log.error(e)
52
66
  nil
@@ -65,6 +79,17 @@ module Ramaze
65
79
 
66
80
  def cache_store(key, value, options = {})
67
81
  ttl = options[:ttl] || 0
82
+
83
+ if ttl > MAX_TTL
84
+ unless @warned
85
+ Log.warn('MemCache cannot set a ttl greater than 2592000 seconds.')
86
+ Log.warn('Modify Ramaze.options.session.ttl to a value <= of that.')
87
+ @warned = true
88
+ end
89
+
90
+ ttl = MAX_TTL
91
+ end
92
+
68
93
  @store.set(key, value, ttl)
69
94
  value
70
95
  rescue ::MemCache::MemCacheError => e
@@ -1,38 +1,53 @@
1
1
  # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
+ require 'sequel'
5
+
4
6
  module Ramaze
5
7
  class Cache
6
8
 
7
9
  # Cache based on a Sequel model using relational databases.
10
+ #
11
+ # Please note that this cache might not work perfectly with Sequel 3.0.0,
12
+ # as the #[] and #[]= methods do not respect serialization.
13
+ # I'll lobby for a change in that direction.
8
14
  class Sequel
9
15
  include Cache::API
10
16
 
11
17
  class Table < ::Sequel::Model(:ramaze_cache)
18
+ plugin :schema
19
+ plugin :serialization
20
+
21
+ serialize_attributes :marshal, :value
22
+
12
23
  set_schema do
13
24
  primary_key :id
14
- string :key
15
- string :value
16
- time :expires
17
25
  index :key, :unique => true
26
+
27
+ String :key
28
+ String :value
29
+ Time :expires
18
30
  end
19
31
 
20
- transform :value => [
21
- lambda{|value| ::Marshal.load(value.unpack('m*')[0]) },
22
- lambda{|value| [::Marshal.dump(value)].pack('m*') }
23
- ]
32
+ def [](column)
33
+ if column == :value
34
+ deserialized_values[column] = deserialize_value(column, @values[column])
35
+ else
36
+ super
37
+ end
38
+ end
24
39
  end
25
40
 
26
41
  # Setup the table, not suitable for multiple apps yet.
27
42
  def cache_setup(host, user, app, name)
28
43
  @namespace = [host, user, app, name].compact.join(':')
29
- Table.create_table unless Table.table_exists?
44
+ Table.create_table?
30
45
  @store = Table
31
46
  end
32
47
 
33
48
  # Wipe out _all_ data in the table, use with care.
34
49
  def cache_clear
35
- Table.delete_all
50
+ Table.delete
36
51
  end
37
52
 
38
53
  # Delete records for given +keys+
@@ -0,0 +1,56 @@
1
+ require "addressable/template"
2
+
3
+ module Ramaze
4
+ # This is a simple prototype-implementation of how we could do routing
5
+ # supported by URI templates.
6
+ #
7
+ # Please see the spec for example usage as it's not integrated yet in any way.
8
+ #
9
+ # What it does is basically that you can give it any URI template and a final
10
+ # mapping, and it will extract the variables from the URI and merge them into
11
+ # the QUERY_STRING, which is parsed again in Ramaze if you issue
12
+ # Request#params.
13
+ #
14
+ # @example given mapping like:
15
+ #
16
+ # map('/customer/{customer_id}/order/{order_id}', '/order/show')
17
+ #
18
+ # @example output of request.params at '/order/show'
19
+ #
20
+ # {'customer_id => '12', 'order_id' => '15'}
21
+ #
22
+ # I haven't explored the full capabilities of the templates yet, but the
23
+ # specs of Addressable::Template suggest that there is a lot to be
24
+ # discovered.
25
+ class AddressableRoute
26
+ def initialize(app, routes = {})
27
+ @app = app
28
+ @routes = {}
29
+
30
+ routes.each{|from, to| map(from, to) }
31
+ end
32
+
33
+ def call(env)
34
+ path_info = env['PATH_INFO']
35
+
36
+ @routes.each do |template, target|
37
+ extracted = template.extract(path_info)
38
+ return dispatch(env, target, extracted) if extracted
39
+ end
40
+
41
+ @app.call(env)
42
+ end
43
+
44
+ def map(from, to)
45
+ @routes[Addressable::Template.new(from)] = to
46
+ end
47
+
48
+ def dispatch(env, target, extracted)
49
+ env['PATH_INFO'] = target
50
+ original = Rack::Utils.parse_query(env['QUERY_STRING'])
51
+ env['QUERY_STRING'] = Rack::Utils.build_query(original.merge(extracted))
52
+
53
+ @app.call(env)
54
+ end
55
+ end
56
+ end
@@ -30,6 +30,8 @@ require 'net/smtp'
30
30
 
31
31
  module Ramaze
32
32
  class EmailHelper
33
+ include Innate::Traited
34
+
33
35
  # Required to be set
34
36
  trait :smtp_server => 'smtp.your-isp.com'
35
37
  trait :smtp_helo_domain => 'your.helo.domain.com'
@@ -59,9 +59,9 @@ module Facebook
59
59
  end while ret.empty? and @server = connect
60
60
 
61
61
  ret = case
62
- when ret == 'true': true
63
- when ret == 'false': false
64
- when ret[0..0] == '"': ret[1..-2]
62
+ when ret == 'true'; true
63
+ when ret == 'false'; false
64
+ when ret[0..0] == '"'; ret[1..-2]
65
65
  else
66
66
  begin
67
67
  JSON::parse(ret)
@@ -168,4 +168,4 @@ module Facebook
168
168
  buf
169
169
  end
170
170
  end
171
- end
171
+ end
@@ -1,4 +1,5 @@
1
1
  require 'sequel'
2
+ require 'sequel/extensions/inflector'
2
3
 
3
4
  module Sequel
4
5
  class Model
@@ -94,14 +94,14 @@ class FormField
94
94
  select(gestalt)
95
95
  else
96
96
  case db_type
97
- when 'varchar', 'integer'
97
+ when /varchar|integer/
98
98
  input(gestalt)
99
- when 'boolean'
99
+ when /boolean/
100
100
  checkbox(gestalt)
101
- when 'string'
101
+ when /string/
102
102
  textarea(gestalt)
103
103
  else
104
- raise "Unsupported type: (#{db_type || hint} : #{field})"
104
+ raise("Unsupported type: (%p : %p)" % [db_type || hint, field])
105
105
  end
106
106
  end
107
107
  end
@@ -7,7 +7,7 @@
7
7
  # Usage:
8
8
  # class Avatar < Sequel::Model
9
9
  # IMAGE = {
10
- # # specifies belongs_to, will create relation and foreign key
10
+ # # specifies many_to_one, will create relation and foreign key
11
11
  #
12
12
  # :owner => :User,
13
13
  #
@@ -51,8 +51,8 @@
51
51
  module SequelImage
52
52
  def self.included(model)
53
53
  args = model::IMAGE
54
- set_foreign_key = args[:foreign_key] || "#{args[:owner]}_id".downcase.to_sym
55
- set_belongs_to = args[:belongs_to] || args[:owner].to_s.downcase.to_sym
54
+ set_foreign_key = args[:foreign_key] || "#{args[:owner]}_id".downcase.to_sym
55
+ set_many_to_one = args[:many_to_one] || args[:owner].to_s.downcase.to_sym
56
56
 
57
57
  # Define schema
58
58
  model.set_schema do
@@ -68,21 +68,19 @@ module SequelImage
68
68
  end
69
69
 
70
70
  # Define Relations
71
- model.belongs_to set_belongs_to
71
+ model.many_to_one set_many_to_one
72
72
 
73
73
  # Define Hooks
74
- model.send(:hooks).clear
75
-
76
- model.before_create do
74
+ model.before_create :generate_thumbnails do
77
75
  generate_thumbnails
78
76
  self.created_at = Time.now
79
77
  end
80
78
 
81
- model.before_save do
79
+ model.before_save :update_time do
82
80
  self.updated_at = Time.now
83
81
  end
84
82
 
85
- model.before_destroy do
83
+ model.before_destroy :cleanup do
86
84
  cleanup if conf[:cleanup]
87
85
  end
88
86
 
@@ -110,7 +108,7 @@ module SequelImage
110
108
  tempfile = file[:tempfile]
111
109
  raise ArgumentError, 'Empty tempfile' if tempfile.size == 0
112
110
 
113
- ext = Ramaze::Tool::MIME.ext_for(type)
111
+ ext = Rack::Mime::MIME_TYPES.invert[type]
114
112
  image.mime = type
115
113
  target_name = image.next_name(File.basename(filename, File.extname(filename)), ext)
116
114
  target_path = File.join(image.public_root, image.path, target_name)
@@ -150,7 +148,7 @@ module SequelImage
150
148
  end
151
149
 
152
150
  def public_root
153
- Ramaze::Global.public_root
151
+ Ramaze.options.roots.first
154
152
  end
155
153
 
156
154
  def filename(size)