Pistos-ramaze 2008.12 → 2009.01

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.
@@ -23,7 +23,14 @@ class Entry < Sequel::Model(:entry)
23
23
  end
24
24
  end
25
25
 
26
- Entry.create_table! unless Entry.table_exists?
26
+ begin
27
+ Entry.create_table!
28
+ rescue Sequel::DatabaseError => e
29
+ if e.message !~ /table.*already exists/
30
+ raise e
31
+ end
32
+ end
33
+
27
34
 
28
35
  if Entry.empty?
29
36
  Entry.add 'Blog created', 'Exciting news today, this blog was created'
@@ -48,6 +48,12 @@ module Model
48
48
  end
49
49
 
50
50
  [Page, OldPage].each do |klass|
51
- klass.create_table unless klass.table_exists?
51
+ begin
52
+ klass.create_table
53
+ rescue Sequel::DatabaseError => e
54
+ if e.message !~ /table.*already exists/
55
+ raise e
56
+ end
57
+ end
52
58
  end
53
59
  end
@@ -0,0 +1,24 @@
1
+ # General Apache options
2
+ Options +FollowSymLinks +ExecCGI
3
+ AddHandler cgi-script cgi rb
4
+ <IfModule mod_fastcgi.c>
5
+ AddHandler fastcgi-script fcgi
6
+ </IfModule>
7
+ <IfModule mod_fcgid.c>
8
+ AddHandler fcgid-script fcgi
9
+ </IfModule>
10
+
11
+ # Redirect all requests not available on the filesystem to Ramaze.
12
+
13
+ RewriteEngine On
14
+ RewriteCond %{REQUEST_FILENAME} !-f
15
+ RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
16
+
17
+ # In case Ramaze experiences terminal errors.
18
+ # Instead of displaying this message you can supply a
19
+ # file here which will be rendered instead.
20
+ #
21
+ # Example:
22
+ # ErrorDocument 500 /500.html
23
+
24
+ ErrorDocument 500 "<h2>Application error</h2>Ramaze failed to start properly"
@@ -52,22 +52,22 @@ EOS
52
52
  str = ""
53
53
  result = Array.new
54
54
  ary.each do |key|
55
- msgid = key.shift.dup
56
- curr_pos = MAX_LINE_LEN
57
- key.each do |e|
58
- if curr_pos + e.size > MAX_LINE_LEN
59
- str << "\n#:"
60
- curr_pos = 3
61
- else
62
- curr_pos += (e.size + 1)
63
- end
64
- str << " " << e
65
- end
66
- msgid.gsub!(/"/, '\"')
67
- msgid.gsub!(/\r/, '')
68
-
69
- str << "\nmsgid \"" << msgid << "\"\n"
70
- str << "msgstr \"\"\n"
55
+ msgid = key.shift.dup
56
+ curr_pos = MAX_LINE_LEN
57
+ key.each do |e|
58
+ if curr_pos + e.size > MAX_LINE_LEN
59
+ str << "\n#:"
60
+ curr_pos = 3
61
+ else
62
+ curr_pos += (e.size + 1)
63
+ end
64
+ str << " " << e
65
+ end
66
+ msgid.gsub!(/"/, '\"')
67
+ msgid.gsub!(/\r/, '')
68
+
69
+ str << "\nmsgid \"" << msgid << "\"\n"
70
+ str << "msgstr \"\"\n"
71
71
  end
72
72
  str
73
73
  end
@@ -81,15 +81,15 @@ EOS
81
81
  msgstr = hash[msgid]
82
82
 
83
83
  msgid.gsub!(/"/, '\"')
84
- msgid.gsub!(/\r/, '')
84
+ msgid.gsub!(/\r/, '')
85
85
 
86
- if msgstr
87
- msgstr.gsub!(/"/, '\"')
88
- msgstr.gsub!(/\r/, '')
89
- end
86
+ if msgstr
87
+ msgstr.gsub!(/"/, '\"')
88
+ msgstr.gsub!(/\r/, '')
89
+ end
90
90
 
91
- str << "\nmsgid \"" << msgid << "\"\n"
92
- str << "msgstr \"" << msgstr << "\"\n"
91
+ str << "\nmsgid \"" << msgid << "\"\n"
92
+ str << "msgstr \"" << msgstr << "\"\n"
93
93
  end
94
94
 
95
95
  str
@@ -16,7 +16,7 @@ module Ramaze
16
16
  # instead, in either case with path as argument.
17
17
 
18
18
  def resolve(path, routed = false)
19
- @routed = routed
19
+ Thread.current[:routed] = routed
20
20
 
21
21
  FILTER.each do |filter|
22
22
  answer = if filter.respond_to?(:call)
@@ -90,7 +90,7 @@ module Ramaze
90
90
  end
91
91
  end
92
92
 
93
- if !@routed and new_path = Route.resolve(path)
93
+ if !Thread.current[:routed] and new_path = Route.resolve(path)
94
94
  Log.dev("Routing from `#{path}' to `#{new_path}'")
95
95
  return resolve(new_path, true)
96
96
  end
@@ -196,9 +196,9 @@ module Ramaze
196
196
  # Example:
197
197
  # request.params
198
198
  # # => {'name' => 'jason', 'age' => '45', 'job' => 'lumberjack'}
199
- # request.sub('name')
199
+ # request.subset('name')
200
200
  # # => {'name' => 'jason'}
201
- # request.sub(:name, :job)
201
+ # request.subset(:name, :job)
202
202
  # # => {'name' => 'jason', 'job' => 'lumberjack'}
203
203
 
204
204
  def subset(*keys)
@@ -206,10 +206,19 @@ module Ramaze
206
206
  params.reject{|k,v| not keys.include?(k) }
207
207
  end
208
208
 
209
+ # Is this an SSL request?
210
+ def ssl?
211
+ env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
212
+ end
213
+
214
+ # Returns 'https' if this is an SSL request and 'http' otherwise.
215
+ def protocol
216
+ ssl? ? 'https' : 'http'
217
+ end
218
+
209
219
  def domain(path = '/')
210
- scheme = env['rack.url_scheme'] || 'http'
211
220
  host = env['HTTP_HOST']
212
- URI("#{scheme}://#{host}#{path}")
221
+ URI("#{protocol}://#{host}#{path}")
213
222
  end
214
223
 
215
224
  # Returns and array of locales from env['HTTP_ACCEPT_LANGUAGE].
@@ -0,0 +1,43 @@
1
+ require 'benchmark'
2
+
3
+ module Ramaze
4
+ module Helper
5
+
6
+ # Little helper to give you a hand when benching parts of actions
7
+
8
+ module Bench
9
+
10
+ # Will first run an empty loop to determine the overhead it imposes, then
11
+ # goes on to yield your block +iterations+ times.
12
+ #
13
+ # The last yielded return value will be returned upon completion of the
14
+ # benchmark and the result of the benchmark itself will be sent to
15
+ # Log.info
16
+ #
17
+ # Example:
18
+ #
19
+ # class MainController < Ramaze::Controller
20
+ # def index
21
+ # @users = bench{ User.all }
22
+ # @tags = bench{ Article.tags }
23
+ # end
24
+ # end
25
+ #
26
+ # This will show something like following in your log:
27
+ # [..] INFO Bench ./start.rb:3:in `index': 0.121163845062256
28
+ # [..] INFO Bench ./start.rb:4:in `index': 2.234987235098341
29
+ #
30
+ # So now we know that the Article.tags call takes the most time and
31
+ # should be improved.
32
+
33
+ def bench(iterations = 1)
34
+ result = nil
35
+ from = caller[0]
36
+ delta = Benchmark.realtime{ iterations.times{ nil }}
37
+ taken = Benchmark.realtime{ iterations.times{ result = yield }}
38
+ Log.info "Bench #{from}: #{taken - delta}"
39
+ return result
40
+ end
41
+ end
42
+ end
43
+ end
@@ -15,7 +15,7 @@ module Ramaze
15
15
  def markaby(ivs = {}, helpers = nil, &block)
16
16
  builder = ::Markaby::Builder
17
17
  builder.extend(Ramaze::Helper::Methods)
18
- builder.send(:helper, :link)
18
+ builder.send(:helper, :redirect, :link, :sendfile, :flash, :cgi, :partial)
19
19
 
20
20
  iv_hash = {}
21
21
  instance_variables.each do |iv|
@@ -165,7 +165,7 @@ module Ramaze
165
165
  text = h(text.to_s)
166
166
 
167
167
  params = Ramaze::Request.current.params.merge(@var.to_s => n)
168
- name = Ramaze::Request.current.request_path
168
+ name = Ramaze::Request.current.path_info
169
169
  hash[:href] = R(name, params)
170
170
 
171
171
  g.a(hash){ text }
@@ -47,7 +47,7 @@ module Ramaze
47
47
  unless target =~ %r!^https?://!
48
48
  target[0,0] = '/' unless target =~ %r!^/!
49
49
  if host = request.env['HTTP_HOST']
50
- target[0,0] = "http://#{host}"
50
+ target[0,0] = "#{request.protocol}://#{host}"
51
51
  end
52
52
  end
53
53
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
1
+ # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
2
  # Copyright (c) 2008 rob@rebeltechnologies.nl
3
3
  # All files in this distribution are subject to the terms of the Ruby license.
4
4
 
@@ -6,46 +6,46 @@ require 'syslog'
6
6
 
7
7
  # Add aliases for the levelnames used by Ramaze logging
8
8
  module Syslog
9
- alias dev debug
10
- alias warn warning
11
- alias error err
12
- module_function :dev, :warn, :error
9
+ alias dev debug
10
+ alias warn warning
11
+ alias error err
12
+ module_function :dev, :warn, :error
13
13
  end
14
14
 
15
15
  module Ramaze
16
- module Logger
17
- # Logger class for writing to syslog. It is a *very* thin wrapper
18
- # around the Syslog library.
19
- class Syslog
20
- include Logging
16
+ module Logger
17
+ # Logger class for writing to syslog. It is a *very* thin wrapper
18
+ # around the Syslog library.
19
+ class Syslog
20
+ include Logging
21
21
 
22
- # Open the syslog library, if it is allready open, we reopen it using the
23
- # new argument list. The argument list is passed on to the Syslog library
24
- # so please check that, and man syslog for detailed information.
25
- # There are 3 parameters:
26
- #
27
- # ident: The identification used in the log file, defaults to $0
28
- # options: defaults to Syslog::LOG_PID | Syslog::LOG_CONS
29
- # facility: defaults to Syslog::LOG_USER
30
- #
31
- def initialize( *args )
32
- ::Syslog.close if ::Syslog.opened?
33
- ::Syslog.open( *args )
34
- end
22
+ # Open the syslog library, if it is allready open, we reopen it using the
23
+ # new argument list. The argument list is passed on to the Syslog library
24
+ # so please check that, and man syslog for detailed information.
25
+ # There are 3 parameters:
26
+ #
27
+ # ident: The identification used in the log file, defaults to $0
28
+ # options: defaults to Syslog::LOG_PID | Syslog::LOG_CONS
29
+ # facility: defaults to Syslog::LOG_USER
30
+ #
31
+ def initialize( *args )
32
+ ::Syslog.close if ::Syslog.opened?
33
+ ::Syslog.open( *args )
34
+ end
35
35
 
36
- # just sends all messages received to ::Syslog
37
- # We simply return if the log was closed for some reason, this behavior
38
- # was copied from Informer. We do not handle levels here. This will
39
- # be done by te syslog daemon based on it's configuration.
40
- def log(tag, *messages)
41
- return if !::Syslog.opened?
42
- ::Syslog.send(tag, *messages)
43
- end
36
+ # just sends all messages received to ::Syslog
37
+ # We simply return if the log was closed for some reason, this behavior
38
+ # was copied from Informer. We do not handle levels here. This will
39
+ # be done by te syslog daemon based on it's configuration.
40
+ def log(tag, *messages)
41
+ return if !::Syslog.opened?
42
+ ::Syslog.send(tag, *messages)
43
+ end
44
44
 
45
- # Has to call the modules singleton-method.
46
- def inspect
47
- ::Syslog.inspect
48
- end
49
- end
45
+ # Has to call the modules singleton-method.
46
+ def inspect
47
+ ::Syslog.inspect
48
+ end
50
49
  end
50
+ end
51
51
  end
@@ -2,5 +2,5 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
- VERSION = "2008.10"
5
+ VERSION = "2009.01"
6
6
  end