zorglub 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88366b3d9072148ff02475d0c49f01308b4c5b93e44c9c144132d967148fd876
4
- data.tar.gz: 86e1a4e383f65d05fa80a871e7246b089bc70708475e6123eaadfd0aa82ec26c
3
+ metadata.gz: be6b53fccd29ce596c15253af31b7c4b7470e1a55075aa34cd541edd54144f57
4
+ data.tar.gz: cda16f4674a73d6ce3659db5e5cf7f51eea5fe0779324990b406046a341b6a04
5
5
  SHA512:
6
- metadata.gz: 2266d5149353d7d1351b944f5f20df05f60425926090cfcb44136f2fa8eb7849317c47c920620654f61e410d17611305f20eaa6aa700ef738a36a9c300b0a3eb
7
- data.tar.gz: 725d026f3eccc26579d1455de735762e4baef7ba172b1e3caf7611e36a941fb005343b2f09a9b638660e2d20c9907046e9080cbbedff12aefc809043572611ad
6
+ metadata.gz: 10c3739c48de2eed8c53c32d703f198ec5fc4a752ce32a36de12c5964664d057ad04f81eeb6ce95b16bd4ae0236e4cd4f02d00c27327372a4479078b1c822e28
7
+ data.tar.gz: 109e27aa1526edff83bd67681f61aced077b2f55a23e13d3b3aaa8ec0962ccf61a8218e0f6f0bcd405cd4c3680e3e370e515ce46718b7d758f86f0322fc1e0bc
data/Changelog CHANGED
@@ -1,3 +1,11 @@
1
+ 2024-10-01 Jérémy Zurcher <jeremy@asynk.ch>
2
+ * release 0.1.7
3
+ * debug to stdout
4
+ * simplify static code path
5
+ * fix error404 msg
6
+ * use keyword arguments
7
+
8
+
1
9
  2024-08-20 Jérémy Zurcher <jeremy@asynk.ch>
2
10
  * release 0.1.6
3
11
  * fix specs
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zorglub (0.1.6)
4
+ zorglub (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/zorglub/node.rb CHANGED
@@ -229,7 +229,7 @@ module Zorglub
229
229
  def call(env)
230
230
  meth, *args = env['PATH_INFO'].sub(%r{^/+}, '').split(%r{/})
231
231
  meth ||= 'index'
232
- $stderr << "=> #{meth}(#{args.join ','})\n" if app.opt :debug
232
+ $stdout << "=> #{meth}(#{args.join ','})\n" if app.opt :debug
233
233
  node = new(env, meth, args)
234
234
  return error404 node, meth unless node.respond_to? meth
235
235
 
@@ -237,26 +237,26 @@ module Zorglub
237
237
  end
238
238
 
239
239
  def partial(env, meth, *args)
240
- node = new env, meth.to_s, args, true
240
+ node = new(env, meth.to_s, args, partial: true)
241
241
  return error404 node, meth unless node.respond_to? meth
242
242
 
243
- node.feed! env[:no_hooks]
243
+ node.feed!(no_hooks: env[:no_hooks])
244
244
  node.content
245
245
  end
246
246
 
247
247
  def error404(node, meth)
248
- $stderr << " !! #{node.class.name}::#{meth} not found\n" if app.opt :debug
248
+ $stdout << " !! #{node.class.name}::#{meth} not found\n" if app.opt :debug
249
249
  resp = node.response
250
250
  resp.status = 404
251
251
  resp['content-type'] = 'text/plain'
252
- resp.write "%<node.class.name>s mapped at %<node.map>p can't respond to : %<node.meth>p"
252
+ resp.write "#{node.class.name} mapped at #{node.map} can't respond to : #{node.meth}"
253
253
  resp.finish
254
254
  end
255
255
  end
256
256
 
257
257
  attr_reader :request, :response, :content, :mime, :state, :engine, :meth, :args
258
258
 
259
- def initialize(env, meth, args, partial = false)
259
+ def initialize(env, meth, args, partial: false)
260
260
  @meth = meth
261
261
  @args = args
262
262
  @partial = partial
@@ -281,16 +281,15 @@ module Zorglub
281
281
  end.finish
282
282
  end
283
283
 
284
- def feed!(no_hooks = false)
284
+ def feed!(no_hooks: false)
285
285
  @state = :pre_cb
286
286
  self.class.call_before_hooks self unless no_hooks
287
287
  @state = :meth
288
288
  @content = send @meth, *@args
289
- static_path = static
290
- if static_path.nil?
291
- compile_page!
292
- else
289
+ if (static_path = static)
293
290
  static_page! static_path
291
+ else
292
+ compile_page!
294
293
  end
295
294
  @state = :post_cb
296
295
  self.class.call_after_hooks self unless no_hooks
@@ -301,7 +300,7 @@ module Zorglub
301
300
  def static_page!(path)
302
301
  if File.exist?(path) && (@cache_lifetime.nil? || @cache_lifetime.zero? ||
303
302
  (Time.now - File.stat(path).mtime) < @cache_lifetime)
304
- $stderr << " * use cache file : #{path}\n" if @debug
303
+ $stdout << " * use cache file : #{path}\n" if @debug
305
304
  content = File.read(path)
306
305
  @content = content.sub(/^@mime:(.*)\n/, '')
307
306
  @mime = ::Regexp.last_match(1)
@@ -309,7 +308,7 @@ module Zorglub
309
308
  compile_page!
310
309
  FileUtils.mkdir_p File.dirname(path)
311
310
  File.open(path, 'w') { |f| f.write("@mime:#{@mime}\n#{@content}") }
312
- $stderr << " * cache file created : #{path}\n" if @debug
311
+ $stdout << " * cache file created : #{path}\n" if @debug
313
312
  end
314
313
  end
315
314
 
@@ -318,9 +317,9 @@ module Zorglub
318
317
  v = view
319
318
  l = layout
320
319
  if @debug
321
- $stderr << " * #{e ? 'use engine' : 'no engine '} : #{e ? e.to_s : ''}\n"
322
- $stderr << " * #{l && File.exist?(l) ? 'use layout' : 'no layout '} : #{l || ''}\n"
323
- $stderr << " * #{v && File.exist?(v) ? 'use view ' : 'no view '} : #{v || ''}\n"
320
+ $stdout << " * #{e ? 'use engine' : 'no engine '} : #{e ? e.to_s : ''}\n"
321
+ $stdout << " * #{l && File.exist?(l) ? 'use layout' : 'no layout '} : #{l || ''}\n"
322
+ $stdout << " * #{v && File.exist?(v) ? 'use view ' : 'no view '} : #{v || ''}\n"
324
323
  end
325
324
  @state = @partial ? :partial : :view
326
325
  @content, mime = e.call(v, self) if e && v && File.exist?(v)
data/lib/zorglub.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  module Zorglub
4
- VERSION = '0.1.6'.freeze
4
+ VERSION = '0.1.7'.freeze
5
5
  end
6
6
 
7
7
  require 'zorglub/node'
data/spec/node_spec.rb CHANGED
@@ -56,6 +56,7 @@ describe Zorglub do
56
56
  it 'should return err404 response when no method found' do
57
57
  expect(Node0.respond_to?('noresponse')).to be_falsey
58
58
  r = Node0.my_call '/noresponse'
59
+ expect(r[2][0]).to eq "Node0 mapped at /node0 can't respond to : noresponse"
59
60
  expect(r[0]).to eq 404
60
61
  end
61
62
 
@@ -294,16 +295,16 @@ describe Zorglub do
294
295
  end
295
296
 
296
297
  it 'debug out should work' do
297
- stderr0 = $stderr.dup
298
- stderrs = StringIO.new
299
- $stderr = stderrs
298
+ stdout0 = $stdout.dup
299
+ stdouts = StringIO.new
300
+ $stdout = stdouts
300
301
  begin
301
302
  APP.opt! :debug, true
302
303
  Node0.my_call '/hello'
303
304
  ensure
304
- $stderr = stderr0
305
+ $stdout = stdout0
305
306
  end
306
- expect(stderrs.string.include?('spec/data/view/node0/hello')).to be true
307
+ expect(stdouts.string.include?('spec/data/view/node0/hello')).to be true
307
308
  end
308
309
  end
309
310
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zorglub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérémy Zurcher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-20 00:00:00.000000000 Z
11
+ date: 2024-10-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A very stripped down version of innate.
14
14
  email: