utopia 0.9.54 → 0.9.55

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.
data/lib/utopia/link.rb CHANGED
@@ -113,7 +113,7 @@ module Utopia
113
113
  def self.metadata(path)
114
114
  links_path = File.join(path, LINKS_YAML)
115
115
  if File.exist?(links_path)
116
- return YAML::load(File.read(links_path))
116
+ return YAML::load(File.read(links_path)) || {}
117
117
  else
118
118
  return {}
119
119
  end
@@ -168,9 +168,11 @@ module Utopia
168
168
 
169
169
  def load_file(path)
170
170
  if path.directory?
171
- base_path = File.join(@root, path.components)
171
+ uri_path = path
172
+ base_path = File.join(@root, uri_path.components)
172
173
  else
173
- base_path = File.join(@root, path.dirname.components)
174
+ uri_path = path.dirname
175
+ base_path = File.join(@root, uri_path.components)
174
176
  end
175
177
 
176
178
  controller_path = File.join(base_path, CONTROLLER_RB)
@@ -178,6 +180,7 @@ module Utopia
178
180
  if File.exist?(controller_path)
179
181
  klass = Class.new(Base)
180
182
  klass.const_set('BASE_PATH', base_path)
183
+ klass.const_set('URI_PATH', uri_path)
181
184
 
182
185
  $LOAD_PATH.unshift(base_path)
183
186
 
@@ -56,6 +56,7 @@ module Utopia
56
56
  attr :path
57
57
  attr :etag
58
58
 
59
+ # Fit in with Rack::Sendfile
59
60
  def to_path
60
61
  full_path
61
62
  end
@@ -136,32 +137,11 @@ module Utopia
136
137
  return result
137
138
  end
138
139
 
139
- # Accelerate the response if sendfile is configured.
140
- def sendfile(request, response)
141
- if @sendfile.respond_to?(:call)
142
- response = @sendfile.call(request.env, response)
143
- elsif @sendfile && request.env['UTOPIA_SENDFILE'] == "X-Sendfile"
144
- response[1]["X-Sendfile"] = response[2].full_path
145
- response[2] = []
146
- elsif @sendfile && request.env['UTOPIA_SENDFILE'] == "X-Accel-Redirect"
147
- response[1]["X-Accel-Redirect"] = response[2].path.to_s
148
- response[2] = []
149
- end
150
-
151
- return response
152
- end
153
-
154
140
  public
155
141
  def initialize(app, options = {})
156
142
  @app = app
157
143
  @root = options[:root] || Utopia::Middleware::default_root
158
-
159
- if options.key? :sendfile
160
- @sendfile = options[:sendfile]
161
- else
162
- @sendfile = (UTOPIA_ENV == :production)
163
- end
164
-
144
+
165
145
  if options[:types]
166
146
  @extensions = load_mime_types(options[:types])
167
147
  else
@@ -236,7 +216,7 @@ module Utopia
236
216
  if file.modified?(env)
237
217
  response_headers["Content-Length"] = file.size.to_s
238
218
 
239
- return sendfile(request, [200, response_headers, file])
219
+ return [200, response_headers, file]
240
220
  else
241
221
  return [304, response_headers, []]
242
222
  end
data/lib/utopia/path.rb CHANGED
@@ -88,6 +88,21 @@ module Utopia
88
88
  end
89
89
  end
90
90
 
91
+ # Computes the difference of the path.
92
+ # /a/b/c - /a/b -> c
93
+ # a/b/c - a/b -> c
94
+ def -(other)
95
+ i = 0
96
+
97
+ while i < other.components.size
98
+ break if @components[i] != other.components[i]
99
+
100
+ i += 1
101
+ end
102
+
103
+ return Path.create(@components[i,@components.size])
104
+ end
105
+
91
106
  def simplify
92
107
  result = absolute? ? [""] : []
93
108
 
@@ -6,7 +6,7 @@ module Utopia
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 9
9
- TINY = 54
9
+ TINY = 55
10
10
 
11
11
  STRING = [MAJOR, MINOR, TINY].join('.')
12
12
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopia
3
3
  version: !ruby/object:Gem::Version
4
- hash: 87
4
+ hash: 85
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 54
10
- version: 0.9.54
9
+ - 55
10
+ version: 0.9.55
11
11
  platform: ruby
12
12
  authors:
13
13
  - Samuel Williams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-26 00:00:00 +12:00
18
+ date: 2011-06-30 00:00:00 +12:00
19
19
  default_executable: utopia
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency