ramaze 2012.12.08b → 2023.01.06

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/README.md +1 -0
  4. data/examples/app/whywiki/spec/whywiki.rb +22 -24
  5. data/examples/app/whywiki/start.rb +10 -9
  6. data/examples/app/whywiki/{template → view}/edit.xhtml +2 -2
  7. data/examples/app/whywiki/view/show.xhtml +20 -0
  8. data/examples/app/wikore/spec/wikore.rb +1 -1
  9. data/guide/AUTHORS +11 -3
  10. data/guide/CHANGELOG +3803 -3592
  11. data/guide/general/sessions.md +42 -0
  12. data/guide/general/upgrading.md +85 -0
  13. data/lib/proto/Gemfile +2 -2
  14. data/lib/ramaze/cache/memcache.rb +3 -3
  15. data/lib/ramaze/cache/moneta.rb +143 -0
  16. data/lib/ramaze/cache/redis.rb +8 -11
  17. data/lib/ramaze/cache/sequel.rb +2 -2
  18. data/lib/ramaze/cache.rb +1 -0
  19. data/lib/ramaze/files.rb +1 -1
  20. data/lib/ramaze/helper/paginate.rb +5 -0
  21. data/lib/ramaze/helper/request_accessor.rb +3 -1
  22. data/lib/ramaze/helper/stack.rb +1 -1
  23. data/lib/ramaze/helper/upload.rb +1 -1
  24. data/lib/ramaze/log/syslog.rb +1 -1
  25. data/lib/ramaze/request.rb +2 -2
  26. data/lib/ramaze/snippets.rb +0 -1
  27. data/lib/ramaze/version.rb +3 -1
  28. data/lib/ramaze/view/nagoro/render_partial.rb +1 -1
  29. data/lib/ramaze.rb +1 -1
  30. data/ramaze.gemspec +19 -15
  31. data/spec/ramaze/cache/moneta.rb +53 -0
  32. data/spec/ramaze/cache/redis.rb +1 -1
  33. data/spec/ramaze/cache/sequel.rb +2 -0
  34. data/spec/ramaze/dispatcher/directory.rb +24 -14
  35. data/spec/ramaze/dispatcher/file.rb +0 -5
  36. data/spec/ramaze/error.rb +13 -17
  37. data/spec/ramaze/helper/paginate.rb +41 -13
  38. data/spec/ramaze/log/syslog.rb +75 -63
  39. data/spec/ramaze/session/redis.rb +2 -2
  40. data/spec/ramaze/session/sequel.rb +2 -0
  41. data/spec/ramaze/view/haml.rb +3 -3
  42. data/spec/ramaze/view/slim.rb +1 -1
  43. metadata +95 -164
  44. data/.gems +0 -28
  45. data/.gitignore +0 -14
  46. data/.mailmap +0 -34
  47. data/.rvmrc +0 -2
  48. data/.travis.yml +0 -16
  49. data/.yardopts +0 -14
  50. data/examples/app/blog/public/.htaccess +0 -24
  51. data/examples/app/whywiki/template/show.xhtml +0 -18
  52. data/lib/ramaze/cache/localmemcache.rb +0 -53
  53. data/lib/ramaze/snippets/ramaze/lru_hash.rb +0 -247
  54. data/spec/ramaze/cache/localmemcache.rb +0 -50
  55. data/spec/ramaze/session/localmemcache.rb +0 -58
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- pkg
2
- .yardoc
3
- doc
4
- ydoc
5
- *~
6
- *.swp
7
- .redcar
8
- *.rbc
9
- database.db
10
- .rbx
11
- .idea/*
12
- *.iml
13
- .rbenv-version
14
- Gemfile.lock
data/.mailmap DELETED
@@ -1,34 +0,0 @@
1
- Ara T. Howard <ara.t.howard@gmail.com> ahoward <>
2
-
3
- <aman@ramaze.net> <aman@tmm1.net>
4
- <aman@ramaze.net> <ramaze@tmm1.net>
5
-
6
- TJ Vanderpoel <bougy.man@gmail.com> <bougyman@falcon.(none)>
7
-
8
- <clinton.nixon@viget.com> <crnixon@gmail.com>
9
-
10
- <clive@crous.co.za> <clive@localhost.(none)>
11
- <clive@crous.co.za> <clive@pc-clive.(none)>
12
- <clive@crous.co.za> <clive@star120.co.za>
13
-
14
- <jonathan.buch@gmail.com> <jo@helloit.fi>
15
- <jonathan.buch@gmail.com> <john@oxyliquit.de>
16
-
17
- <lasso@lassoweb.se> <lasso@lasso-laptop.(none)>
18
-
19
- James Tucker <jftucker@gmail.com> <raggi@mbk.local>
20
- James Tucker <jftucker@gmail.com> raggi
21
-
22
- Martin Hilbig <blueonyx@dev-area.net> Martin Hilbig blueonyx@dev-area.net <>
23
-
24
- Lee Jarvis <injekt.me@gmail.com> <ljjarvis@gmail.com>
25
- Lee Jarvis <injekt.me@gmail.com> Lee Jarvis injekt.me@gmail.com <>
26
-
27
- Michael Fellinger <m.fellinger@gmail.com> <m.fellinger@gmail.com>
28
- Michael Fellinger <m.fellinger@gmail.com> <manveru@sigma.localdomain>
29
- Michael Fellinger <m.fellinger@gmail.com> <manveru@weez-int.com>
30
- Michael Fellinger <m.fellinger@gmail.com> Michael Fellinger m.fellinger@gmail.com <>
31
- Yorick Peterse <yorickpeterse@gmail.com> YorickPeterse <yorickpeterse@gmail.com>
32
- Yorick Peterse <yorickpeterse@gmail.com> YorickPeterse <info@yorickpeterse.com>
33
- Yorick Peterse <yorickpeterse@gmail.com> Yorick Peterse <info@yorickpeterse.com>
34
- Yorick Peterse <yorickpeterse@gmail.com> Yorick Peterse <yorick@isset.nl>
data/.rvmrc DELETED
@@ -1,2 +0,0 @@
1
- rvm --install --create use 1.9.3@ramaze
2
- [[ -s .gems ]] && rvm gemset import .gems
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- script: 'rake bacon'
3
- rvm:
4
- - 1.9.2
5
- - 1.9.3
6
- - jruby-19mode
7
- - rbx-19mode
8
-
9
- notifications:
10
- email:
11
- - yorickpeterse@gmail.com
12
- - mf@rubyists.com
13
-
14
- branches:
15
- only:
16
- - master
data/.yardopts DELETED
@@ -1,14 +0,0 @@
1
- ./lib/ramaze/**/*.rb ./lib/ramaze.rb
2
- -m markdown
3
- -M rdiscount
4
- -o ./doc
5
- -r ./README.md
6
- --private
7
- --protected
8
- --asset ./guide/_static:_static
9
- --asset ./guide/css/common.css:css/common.css
10
- -
11
- ./guide/**/*.md
12
- ./guide/AUTHORS
13
- ./guide/CHANGELOG
14
- ./guide/LICENSE
@@ -1,24 +0,0 @@
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"
@@ -1,18 +0,0 @@
1
- <html>
2
- <head>
3
- <title>MicroWiki #{@page}</title>
4
- <style>
5
- a.exists{ color: #00f; }
6
- a.nonexists{ color: #f00; }
7
- </style>
8
- </head>
9
- <body>
10
- <a href="/show/Home" unless="@page == 'Home'">&lt; Home</a>
11
- <h1>#{@page}</h1>
12
- <a href="#@edit_link" if="@text.empty?">Create #@page</a>
13
- <div unless="@text.empty?">
14
- <a href="#@edit_link">Edit #@page</a>
15
- #@text
16
- </div>
17
- </body>
18
- </html>
@@ -1,53 +0,0 @@
1
- # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
- # All files in this distribution are subject to the terms of the MIT license.
3
-
4
- require 'localmemcache'
5
-
6
- module Ramaze
7
- class Cache
8
- # Cache based on the localmemcache library which utilizes mmap to share
9
- # strings in memory between ruby instances.
10
- class LocalMemCache
11
- include Cache::API
12
-
13
- OPTIONS = {
14
- :size_mb => 1024,
15
- :serialize => true,
16
- :serializer => ::Marshal, # something that responds to ::load and ::dump
17
- }
18
-
19
- # Connect to localmemcache
20
- def cache_setup(host, user, app, name)
21
- @namespace = [host, user, app, name].compact.join('-')
22
- options = {:namespace => @namespace}.merge(OPTIONS)
23
-
24
- @serialize = options.delete(:serialize)
25
- @serializer = options.delete(:serializer)
26
- @store = ::LocalMemCache.new(options)
27
- end
28
-
29
- # Wipe out _all_ data in localmemcached, use with care.
30
- def cache_clear
31
- @store.clear
32
- end
33
-
34
- def cache_delete(*args)
35
- super { |key| @store.delete(key.to_s); nil }
36
- end
37
-
38
- # NOTE:
39
- # * We have no way of knowing whether the value really is nil, we
40
- # assume you wouldn't cache nil and return the default instead.
41
- def cache_fetch(*args)
42
- super { |key|
43
- value = @store[key.to_s]
44
- @serializer.load(value) if value
45
- }
46
- end
47
-
48
- def cache_store(*args)
49
- super { |key, value| @store[key.to_s] = @serializer.dump(value) }
50
- end
51
- end # LocalMemCache
52
- end # Cache
53
- end # Ramaze
@@ -1,247 +0,0 @@
1
- module Ramaze
2
- # A Hash-alike LRU cache that provides fine-grained control over content
3
- # restrictions.
4
- #
5
- # It allows you to set:
6
- # * a maximum number of elements
7
- # * the maximum amount of memory used for all elements
8
- # * the allowed memory-size per element
9
- # * time to live
10
- #
11
- # Differences to the original implementation include:
12
- # * The Cache is now a Struct for speed
13
- # * Object memory size is obtained via Marshal::dump instead of #to_s
14
- #
15
- # Note that due to calculating object size with Marshal, you might have to do
16
- # some evaluation as to how large your values will be when marshaled, for
17
- # example a String will have String#size + 10. This differs from object to
18
- # object and between versions of Marshal, so be generous.
19
- #
20
- # Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org>
21
- # Copyright (c) 2009 Michael Fellinger <manveru@rubyists.com>
22
- #
23
- # You may redistribute it and/or modify it under the same terms as Ruby.
24
- class LRUHash < Struct.new(:max_total, :max_value, :max_count, :expiration,
25
- :hook, :objs, :total_size, :list, :hits, :misses)
26
- CacheObject = Struct.new(:content, :size, :atime)
27
- VERSION = '0.3'
28
-
29
- # On 1.8 we raise IndexError, on 1.9 we raise KeyError
30
- KeyError = Module.const_defined?(:KeyError) ? KeyError : IndexError
31
-
32
- include Enumerable
33
-
34
- def initialize(options = {}, &hook)
35
- self.max_value = options[:max_value]
36
- self.max_total = options[:max_total]
37
- self.max_count = options[:max_count]
38
- self.expiration = options[:expiration]
39
-
40
- avoid_insane_options
41
-
42
- self.hook = hook
43
-
44
- self.objs = {}
45
- self.list = []
46
-
47
- self.total_size = 0
48
- self.hits = self.misses = 0
49
- end
50
-
51
- def key?(key)
52
- objs.key?(key)
53
- end
54
-
55
- def value?(given_value)
56
- objs.each do |key, obj|
57
- return true if given_value == obj.content
58
- end
59
-
60
- false
61
- end
62
-
63
- def index(given_value)
64
- objs.each do |key, obj|
65
- return key if given_value == obj.content
66
- end
67
-
68
- nil
69
- end
70
-
71
- def keys
72
- objs.keys
73
- end
74
-
75
- def size
76
- objs.size
77
- end
78
- alias length size
79
-
80
- def to_hash
81
- objs.dup
82
- end
83
-
84
- def values
85
- objs.map{|key, obj| obj.content }
86
- end
87
-
88
- def delete(key)
89
- return unless objs.key?(key)
90
- obj = objs[key]
91
-
92
- hook.call(key, obj.content) if hook
93
- self.total_size -= obj.size
94
- objs.delete key
95
-
96
- list.delete_if{|list_key| key == list_key }
97
-
98
- obj.content
99
- end
100
- alias invalidate delete
101
-
102
- def clear
103
- objs.each{|key, obj| hook.call(key, obj) } if hook
104
- objs.clear
105
- list.clear
106
- self.total_size = 0
107
- end
108
- alias invalidate_all clear
109
-
110
- def expire
111
- return unless expiration
112
- now = Time.now.to_i
113
-
114
- list.each_with_index do |key, index|
115
- break unless (objs[key].atime + expiration) <= now
116
- invalidate key
117
- end
118
- end
119
-
120
- def [](key)
121
- expire
122
-
123
- unless objs.key?(key)
124
- self.misses += 1
125
- return
126
- end
127
-
128
- obj = objs[key]
129
- obj.atime = Time.now.to_i
130
-
131
- list.delete_if{|list_key| key == list_key }
132
- list << key
133
-
134
- self.hits += 1
135
- obj.content
136
- end
137
-
138
- def []=(key, obj)
139
- expire
140
-
141
- invalidate key if key?(key)
142
-
143
- size = Marshal.dump(obj).size
144
-
145
- if max_value && max_value < max_total
146
- warn "%p isn't cached because it exceeds max_value %p" % [obj, max_value]
147
- return obj
148
- end
149
-
150
- if max_value.nil? && max_total && max_total < size
151
- warn "%p isn't cached because it exceeds max_total: %p" % [obj, max_total]
152
- return obj
153
- end
154
-
155
- invalidate list.first if max_count && max_count == list.size
156
-
157
- self.total_size += size
158
-
159
- if max_total
160
- invalidate list.first until total_size < max_total
161
- end
162
-
163
- objs[key] = CacheObject.new(obj, size, Time.now.to_i)
164
- list << key
165
-
166
- obj
167
- end
168
-
169
- def store(key, value)
170
- self[key] = value
171
- end
172
-
173
- def each_pair
174
- return enum_for(:each_pair) unless block_given?
175
- objs.each{|key, obj| yield key, obj.content }
176
- self
177
- end
178
-
179
- def each_key(&block)
180
- return enum_for(:each_key) unless block_given?
181
- objs.each_key{|key| yield key }
182
- self
183
- end
184
-
185
- def each_value
186
- return enum_for(:each_value) unless block_given?
187
- objs.each_value{|obj| yield obj.content }
188
- self
189
- end
190
-
191
- def empty?
192
- objs.empty?
193
- end
194
-
195
- # Note that this method diverges from the default behaviour of the Ruby Hash.
196
- # If the cache doesn't find content for the given key, it will store the
197
- # given default instead. Optionally it also takes a block, the return value
198
- # of the block is then stored and returned.
199
- #
200
- # @example
201
- #
202
- # lru = LRUHash.new
203
- # lru.fetch(:a) # => KeyError: key not found: :a
204
- # lru.fetch(:a, :b) # => :b
205
- # lru.fetch(:a) # => :b
206
- # lru.fetch(:c){|key| key.to_s } # => 'c'
207
- # lru.fetch(:c) # => 'c'
208
- def fetch(key, default = (p_default = true; nil))
209
- if key?(key)
210
- value = self[key]
211
- elsif p_default.nil?
212
- value = self[key] = default
213
- elsif block_given?
214
- value = self[key] = yield(key)
215
- else
216
- raise KeyError, "key not found: %p" % [key]
217
- end
218
-
219
- value
220
- end
221
-
222
- def statistics
223
- {:size => total_size, :count => list.size, :hits => hits, :misses => misses}
224
- end
225
-
226
- private
227
-
228
- # Sanity checks.
229
- def avoid_insane_options
230
- if (max_value && max_total) && max_value > max_total
231
- raise ArgumentError, "max_value exceeds max_total (#{max_value} > #{max_total})"
232
- end
233
- if max_value && max_value <= 0
234
- raise ArgumentError, "invalid max_value `#{max_value}'"
235
- end
236
- if max_total && max_total <= 0
237
- raise ArgumentError, "invalid max_total `#{max_total}'"
238
- end
239
- if max_count && max_count <= 0
240
- raise ArgumentError, "invalid max_count `#{max_count}'"
241
- end
242
- if expiration && expiration <= 0
243
- raise ArgumentError, "invalid expiration `#{expiration}'"
244
- end
245
- end
246
- end # LRUHash
247
- end # Ramaze
@@ -1,50 +0,0 @@
1
- # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
- # All files in this distribution are subject to the terms of the MIT license.
3
-
4
- require File.expand_path('../../../../spec/helper', __FILE__)
5
-
6
- spec_require 'localmemcache'
7
-
8
- describe Ramaze::Cache::LocalMemCache do
9
- Ramaze.options.cache.names = [:one, :two]
10
- Ramaze.options.cache.default = Ramaze::Cache::LocalMemCache
11
- Ramaze.setup_dependencies
12
-
13
- cache = Ramaze::Cache.one
14
- hello = 'Hello, World!'
15
-
16
- should 'store without ttl' do
17
- cache.store(:hello, hello).should.equal hello
18
- end
19
-
20
- should 'fetch' do
21
- cache.fetch(:hello).should.equal hello
22
- end
23
-
24
- should 'delete' do
25
- cache.delete(:hello)
26
- cache.fetch(:hello).should.equal nil
27
- end
28
-
29
- should 'delete two key/value pairs at once' do
30
- cache.store(:hello, hello).should.equal hello
31
- cache.store(:ramaze, 'ramaze').should.equal 'ramaze'
32
- cache.delete(:hello, :ramaze)
33
- cache.fetch(:hello).should.equal nil
34
- cache.fetch(:innate).should.equal nil
35
- end
36
-
37
- should 'store with ttl' do
38
- cache.store(:hello, @hello, :ttl => 0.2)
39
- cache.fetch(:hello).should.equal @hello
40
- sleep 0.3
41
- cache.fetch(:hello).should.equal nil
42
- end
43
-
44
- should 'clear' do
45
- cache.store(:hello, @hello)
46
- cache.fetch(:hello).should.equal @hello
47
- cache.clear
48
- cache.fetch(:hello).should.equal nil
49
- end
50
- end
@@ -1,58 +0,0 @@
1
- require File.expand_path('../../../../spec/helper', __FILE__)
2
- spec_require 'sequel'
3
-
4
- class SpecSession < Ramaze::Controller
5
- map '/'
6
- engine :None
7
-
8
- def index
9
- 'No session here'
10
- end
11
-
12
- def init
13
- session[:counter] = 0
14
- end
15
-
16
- def view
17
- session[:counter]
18
- end
19
-
20
- def increment
21
- session[:counter] += 1
22
- end
23
-
24
- def decrement
25
- session[:counter] -= 1
26
- end
27
-
28
- def reset
29
- session.clear
30
- end
31
- end
32
-
33
- Ramaze::Cache.options.session = Ramaze::Cache::LocalMemCache
34
-
35
- describe 'Sessions with Ramaze::Cache::LocalMemCache' do
36
- behaves_like :rack_test
37
-
38
- should 'initiate session as needed' do
39
- get '/'
40
- last_response.body.should == 'No session here'
41
- last_response['Set-Cookie'].should == nil
42
-
43
- get('/init')
44
- last_response.body.should == '0'
45
-
46
- 1.upto(10) do |n|
47
- get('/increment').body.should == n.to_s
48
- end
49
-
50
- get('/reset')
51
- get('/view').body.should == ''
52
- get('/init').body.should == '0'
53
-
54
- -1.downto(-10) do |n|
55
- get('/decrement').body.should == n.to_s
56
- end
57
- end
58
- end