egalite 1.5.13 → 1.5.18
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.
- checksums.yaml +5 -5
- data/lib/egalite.rb +1 -1
- data/lib/egalite/cache.rb +22 -4
- data/lib/egalite/helper.rb +2 -2
- data/lib/egalite/http.rb +17 -6
- data/lib/egalite/version.rb +1 -1
- data/test/test_cache.rb +91 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f58aca213d75a5b20237d8c539da701bcfffc30b3a4284a1648ef10ce81e1381
|
4
|
+
data.tar.gz: a4e49c8321c915201a3acfd1a40a6e97273540d61c19e347588196345a19a5c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ea8ceb6da4f2f96885cfa443205e0015a3093183b793324de973ed2fec6c3edcf1b94e8fc4e37226e8c4cb89509aaffdc55bf8cf1bf81923ca4c182ec0f327e
|
7
|
+
data.tar.gz: dc24f4b3d897509da313ca4e256b0612f9e0d536cda742580e704bb23f41797a273bed18145ffaa911d70aa43dd42b14cb0aa8d9ed7fcea0b3857fba51523da8
|
data/lib/egalite.rb
CHANGED
@@ -200,7 +200,7 @@ class Controller
|
|
200
200
|
EgaliteResponse.new(:delegate, params)
|
201
201
|
end
|
202
202
|
def include(params)
|
203
|
-
raw(req.handler.inner_dispatch(req, params)[2].
|
203
|
+
raw(req.handler.inner_dispatch(req, params)[2].join)
|
204
204
|
end
|
205
205
|
def send_file(path, content_type = nil)
|
206
206
|
ext = File.extname(path)[1..-1]
|
data/lib/egalite/cache.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
CREATE TABLE controller_cache (
|
6
6
|
id SERIAL PRIMARY KEY,
|
7
7
|
inner_path TEXT NOT NULL,
|
8
|
+
query_string TEXT,
|
8
9
|
language TEXT,
|
9
10
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
10
11
|
content TEXT NOT NULL
|
@@ -19,6 +20,14 @@ module Egalite
|
|
19
20
|
def create_table(db, opts = {})
|
20
21
|
table = opts[:table_name] || :controller_cache
|
21
22
|
|
23
|
+
create_table_without_query(db, opts)
|
24
|
+
db.alter_table(table) {
|
25
|
+
add_column :query_string, :varchar
|
26
|
+
}
|
27
|
+
end
|
28
|
+
def create_table_without_query(db, opts = {})
|
29
|
+
table = opts[:table_name] || :controller_cache
|
30
|
+
|
22
31
|
db.create_table(table) {
|
23
32
|
primary_key :id, :integer, :auto_increment => true
|
24
33
|
column :inner_path, :varchar
|
@@ -38,14 +47,21 @@ module Egalite
|
|
38
47
|
def self.included(base)
|
39
48
|
base.extend(ClassMethods)
|
40
49
|
end
|
41
|
-
def __controller_cache__dataset
|
50
|
+
def __controller_cache__dataset(options)
|
42
51
|
table = Egalite::ControllerCache.table
|
43
52
|
dataset = table.filter(:inner_path => req.inner_path)
|
53
|
+
if options[:with_query]
|
54
|
+
dataset = dataset.filter(:query_string => __query_string(options))
|
55
|
+
end
|
44
56
|
if req.language
|
45
57
|
dataset = dataset.filter(:language => req.language)
|
46
58
|
end
|
47
59
|
dataset
|
48
60
|
end
|
61
|
+
def __query_string(options)
|
62
|
+
return nil unless options[:with_query] and not req.rack_request.query_string.empty?
|
63
|
+
req.rack_request.query_string
|
64
|
+
end
|
49
65
|
def before_filter
|
50
66
|
cache = self.class.controller_cache_actions[req.action_method]
|
51
67
|
if cache and Egalite::ControllerCache.table
|
@@ -53,7 +69,7 @@ module Egalite
|
|
53
69
|
if result != true
|
54
70
|
return result
|
55
71
|
end
|
56
|
-
dataset = __controller_cache__dataset
|
72
|
+
dataset = __controller_cache__dataset(cache)
|
57
73
|
record = dataset.first
|
58
74
|
return true unless record
|
59
75
|
return true if record[:updated_at] < (Time.now - cache[:expire])
|
@@ -66,13 +82,16 @@ module Egalite
|
|
66
82
|
html = super(html)
|
67
83
|
cache = self.class.controller_cache_actions[req.action_method]
|
68
84
|
if cache and Egalite::ControllerCache.table
|
69
|
-
dataset = __controller_cache__dataset
|
85
|
+
dataset = __controller_cache__dataset(cache)
|
70
86
|
data = {
|
71
87
|
:inner_path => req.inner_path,
|
72
88
|
:language => req.language,
|
73
89
|
:updated_at => Time.now,
|
74
90
|
:content => html,
|
75
91
|
}
|
92
|
+
if cache[:with_query]
|
93
|
+
data[:query_string] = __query_string(cache)
|
94
|
+
end
|
76
95
|
if dataset.count > 0
|
77
96
|
dataset.update(data)
|
78
97
|
else
|
@@ -83,4 +102,3 @@ module Egalite
|
|
83
102
|
end
|
84
103
|
end
|
85
104
|
end
|
86
|
-
|
data/lib/egalite/helper.rb
CHANGED
@@ -191,10 +191,10 @@ class FormHelper
|
|
191
191
|
end
|
192
192
|
def radio(name, choice, opts = {})
|
193
193
|
selected = (@data[name] == choice)
|
194
|
-
selected = (opts[:default] == choice) || opts[:selected] if @data[name] == nil
|
194
|
+
selected = (opts[:default] == choice) || opts[:selected] || opts[:checked] if @data[name] == nil
|
195
195
|
|
196
196
|
attrs = opt_as_hash(opts)
|
197
|
-
attrs[:
|
197
|
+
attrs[:checked] = 'checked' if selected
|
198
198
|
attrs[:name] = expand_name(name)
|
199
199
|
attrs[:value] = choice
|
200
200
|
attrs[:type] = 'radio'
|
data/lib/egalite/http.rb
CHANGED
@@ -11,6 +11,21 @@ module Egalite
|
|
11
11
|
http.use_ssl = true
|
12
12
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
13
13
|
end
|
14
|
+
if options[:continue_timeout]
|
15
|
+
http.continue_timeout = options[:continue_timeout]
|
16
|
+
end
|
17
|
+
if options[:keep_alive_timeout]
|
18
|
+
http.keep_alive_timeout = options[:keep_alive_timeout]
|
19
|
+
end
|
20
|
+
if options[:open_timeout]
|
21
|
+
http.open_timeout = options[:open_timeout]
|
22
|
+
end
|
23
|
+
if options[:read_timeout]
|
24
|
+
http.read_timeout = options[:read_timeout]
|
25
|
+
end
|
26
|
+
if options[:ssl_timeout]
|
27
|
+
http.ssl_timeout = options[:ssl_timeout]
|
28
|
+
end
|
14
29
|
[http, uri]
|
15
30
|
end
|
16
31
|
def self.parse_options(options)
|
@@ -37,9 +52,7 @@ module Egalite
|
|
37
52
|
def self.get(url, options = {})
|
38
53
|
params = options[:params]
|
39
54
|
if params.is_a?(Hash)
|
40
|
-
params = params
|
41
|
-
"#{k}=#{v}"
|
42
|
-
}.join("&")
|
55
|
+
params = URI.encode_www_form(params)
|
43
56
|
end
|
44
57
|
if params.is_a?(String)
|
45
58
|
if url =~ /\?/
|
@@ -57,9 +70,7 @@ module Egalite
|
|
57
70
|
def self.post(url, body = nil, options = {})
|
58
71
|
uri = parse_url(url,options)
|
59
72
|
if body.is_a?(Hash)
|
60
|
-
body = body
|
61
|
-
"#{k}=#{v}"
|
62
|
-
}.join("&")
|
73
|
+
body = URI.encode_www_form(body)
|
63
74
|
end
|
64
75
|
parse_options(options)
|
65
76
|
(http, uri) = parse_url(url, options)
|
data/lib/egalite/version.rb
CHANGED
data/test/test_cache.rb
CHANGED
@@ -25,6 +25,19 @@ class TestCacheController < Egalite::Controller
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
class TestCachewithqueryController < Egalite::Controller
|
29
|
+
include Egalite::ControllerCache
|
30
|
+
|
31
|
+
cache_action :get, :expire => 1, :with_query => true
|
32
|
+
|
33
|
+
def get
|
34
|
+
"#{Time.now.to_i}.#{Time.now.usec}"
|
35
|
+
end
|
36
|
+
def nocache
|
37
|
+
"#{Time.now.to_i}.#{Time.now.usec}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
28
41
|
class CacheController < Egalite::Controller
|
29
42
|
include Egalite::ControllerCache
|
30
43
|
|
@@ -41,6 +54,47 @@ class CacheController < Egalite::Controller
|
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
57
|
+
# compatibility test
|
58
|
+
class T_CacheWithoutQuery < Test::Unit::TestCase
|
59
|
+
include Rack::Test::Methods
|
60
|
+
|
61
|
+
def app
|
62
|
+
db = Sequel.sqlite
|
63
|
+
Egalite::ControllerCache.create_table_without_query(db)
|
64
|
+
Egalite::ControllerCache.table = db[:controller_cache]
|
65
|
+
Egalite::Handler.new
|
66
|
+
end
|
67
|
+
def test_cache
|
68
|
+
# test cache is not working
|
69
|
+
get "/test/cache/nocache"
|
70
|
+
a = last_response.body
|
71
|
+
sleep 0.1
|
72
|
+
get "/test/cache/nocache"
|
73
|
+
b = last_response.body
|
74
|
+
assert_not_equal a,b
|
75
|
+
|
76
|
+
# test cache is working
|
77
|
+
get "/test/cache/"
|
78
|
+
a = last_response.body
|
79
|
+
sleep 0.1
|
80
|
+
get "/test/cache/"
|
81
|
+
b = last_response.body
|
82
|
+
assert_equal a,b
|
83
|
+
sleep 2
|
84
|
+
get "/test/cache/"
|
85
|
+
c = last_response.body
|
86
|
+
assert_not_equal a,c
|
87
|
+
|
88
|
+
# test cache is not working for different url
|
89
|
+
get "/test/cache/1"
|
90
|
+
a = last_response.body
|
91
|
+
sleep 0.1
|
92
|
+
get "/test/cache/2"
|
93
|
+
b = last_response.body
|
94
|
+
assert_not_equal a,b
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
44
98
|
class T_Cache < Test::Unit::TestCase
|
45
99
|
include Rack::Test::Methods
|
46
100
|
|
@@ -79,6 +133,43 @@ class T_Cache < Test::Unit::TestCase
|
|
79
133
|
b = last_response.body
|
80
134
|
assert_not_equal a,b
|
81
135
|
end
|
136
|
+
def test_cache_with_query
|
137
|
+
# test cache is not working
|
138
|
+
get "/test/cachewithquery/nocache"
|
139
|
+
a = last_response.body
|
140
|
+
sleep 0.1
|
141
|
+
get "/test/cachewithquery/nocache"
|
142
|
+
b = last_response.body
|
143
|
+
assert_not_equal a,b
|
144
|
+
|
145
|
+
# test cache is working
|
146
|
+
get "/test/cachewithquery?a=1"
|
147
|
+
a = last_response.body
|
148
|
+
sleep 0.1
|
149
|
+
get "/test/cachewithquery?a=1"
|
150
|
+
b = last_response.body
|
151
|
+
assert_equal a,b
|
152
|
+
sleep 2
|
153
|
+
get "/test/cachewithquery?a=1"
|
154
|
+
c = last_response.body
|
155
|
+
assert_not_equal a,c
|
156
|
+
|
157
|
+
# test cache is not working for different url
|
158
|
+
get "/test/cachewithquery?a=1"
|
159
|
+
a = last_response.body
|
160
|
+
sleep 0.1
|
161
|
+
get "/test/cachewithquery"
|
162
|
+
b = last_response.body
|
163
|
+
assert_not_equal a,b
|
164
|
+
sleep 0.1
|
165
|
+
get "/test/cachewithquery?a=2"
|
166
|
+
c = last_response.body
|
167
|
+
assert_not_equal a,c
|
168
|
+
sleep 0.1
|
169
|
+
get "/test/cachewithquery?a=1&b=2"
|
170
|
+
d = last_response.body
|
171
|
+
assert_not_equal a,d
|
172
|
+
end
|
82
173
|
end
|
83
174
|
|
84
175
|
# テンプレートでのテスト
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: egalite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shunichi Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -152,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.2.2
|
155
|
+
rubygems_version: 3.0.3
|
157
156
|
signing_key:
|
158
157
|
specification_version: 4
|
159
158
|
summary: Egalite - yet another web application framework.
|