innate 2012.12 → 2013.02

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,11 @@ rvm:
6
6
  - 1.8.7
7
7
  - 1.9.2
8
8
  - 1.9.3
9
- - ruby-head
9
+ - jruby-18mode
10
+ - jruby-19mode
10
11
  - rbx-18mode
11
- - ree
12
- - jruby
12
+ - rbx-19mode
13
+ - ruby-head
13
14
  notifications:
14
15
  email:
15
16
  - mf@rubyists.com
data/AUTHORS CHANGED
@@ -1,9 +1,9 @@
1
1
  Following persons have contributed to innate.
2
2
  (Sorted by number of submitted patches, then alphabetically)
3
3
 
4
- 814 Michael Fellinger <m.fellinger@gmail.com>
4
+ 819 Michael Fellinger <m.fellinger@gmail.com>
5
5
  31 Tadahiko Uehara <kikofx@gmail.com>
6
- 16 Yorick Peterse <yorickpeterse@gmail.com>
6
+ 21 Yorick Peterse <yorickpeterse@gmail.com>
7
7
  9 Lee Jarvis <injekt.me@gmail.com>
8
8
  8 Pistos <gitsomegrace.5.pistos@geoshell.com>
9
9
  5 injekt <injekt.me@gmail.com>
data/CHANGELOG CHANGED
@@ -1,3 +1,97 @@
1
+ [1a2ee39 | 2013-02-07 00:10:01 UTC] Michael Fellinger <m.fellinger@gmail.com>
2
+
3
+ * Version 2013.02
4
+
5
+ [64ca67a | 2013-01-29 23:34:26 UTC] Michael Fellinger <m.fellinger@gmail.com>
6
+
7
+ * don't do CI for REE, it's not supported anymore, add rbx and jruby 1.9
8
+
9
+ [079975c | 2013-01-29 21:57:39 UTC] Yorick Peterse <yorickpeterse@gmail.com>
10
+
11
+ * Preserve values when calling render_full.
12
+
13
+ Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
14
+
15
+ [a90d3f9 | 2013-01-29 21:53:16 UTC] Yorick Peterse <yorickpeterse@gmail.com>
16
+
17
+ * Fix for generting URLs using anchor().
18
+
19
+ Instead of always appending "?" to the URL the anchor() method should only do
20
+ so when there actually is a query string.
21
+
22
+ Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
23
+
24
+ [d2aeb7f | 2013-01-29 21:17:08 UTC] Yorick Peterse <yorickpeterse@gmail.com>
25
+
26
+ * Caching of provides and method arities.
27
+
28
+ Caching of a controller's provide handlers as well as the method arities can
29
+ lead to a nice performance boost of around 300 transactions/second using the
30
+ following benchmark:
31
+
32
+ require 'innate'
33
+
34
+ Innate.middleware :live do
35
+ run Innate.core
36
+ end
37
+
38
+ Innate::Log.level = Logger::ERROR
39
+ Innate.options.mode = :live
40
+ ENV['RACK_ENV'] = 'none'
41
+
42
+ class MainController
43
+ Innate.node('/', self)
44
+
45
+ def index
46
+ return 'index'
47
+ end
48
+ end
49
+
50
+ [:fast_mappings, :cache_provides, :cache_method_arities].each do |key|
51
+ MainController.ancestral_trait[key] = true
52
+ end
53
+
54
+ Innate.start(:adapter => :thin)
55
+
56
+ Benchmarking this was done by running `siege -c 10 -t 5s -b HOST` and would
57
+ initially result in around 1700 trans/sec. When using this commit this sits
58
+ between 2000/2100 trans/sec.
59
+
60
+ To prevent any potential issues the caching of provides and method aritites is
61
+ disabled by default.
62
+
63
+ See Github issue #7 for more information.
64
+
65
+ Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
66
+
67
+ [06dd4c5 | 2013-01-29 18:25:49 UTC] Yorick Peterse <yorickpeterse@gmail.com>
68
+
69
+ * Revert action caching.
70
+
71
+ Instead of caching the entire action instance (which is modified further down
72
+ the chain) various parts that make up this process will be cached instead
73
+ (where possible).
74
+
75
+ Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
76
+
77
+ [32440b0 | 2013-01-15 18:38:41 UTC] Michael Fellinger <m.fellinger@gmail.com>
78
+
79
+ * prevent memory leak from action caching
80
+
81
+ [040d084 | 2013-01-15 18:37:19 UTC] Michael Fellinger <m.fellinger@gmail.com>
82
+
83
+ * clean up LRUHash a bit
84
+
85
+ [a136a72 | 2013-01-14 20:06:22 UTC] Michael Fellinger <m.fellinger@gmail.com>
86
+
87
+ * build middleware only once
88
+
89
+ [8aea7cb | 2013-01-14 18:31:37 UTC] Yorick Peterse <yorickpeterse@gmail.com>
90
+
91
+ * Only compile middleware for the current mode.
92
+
93
+ Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
94
+
1
95
  [1da947d | 2012-12-07 21:25:01 UTC] Michael Fellinger <m.fellinger@gmail.com>
2
96
 
3
97
  * Version 2012.12
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "innate"
5
- s.version = "2012.12"
5
+ s.version = "2013.02"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Michael 'manveru' Fellinger"]
9
- s.date = "2012-12-07"
9
+ s.date = "2013-02-07"
10
10
  s.description = "Simple, straight-forward base for web-frameworks."
11
11
  s.email = "m.fellinger@gmail.com"
12
12
  s.files = [".gems", ".gitignore", ".load_gemset", ".rvmrc", ".travis.yml", "AUTHORS", "CHANGELOG", "COPYING", "MANIFEST", "README.md", "Rakefile", "example/app/retro_games.rb", "example/app/todo/layout/default.xhtml", "example/app/todo/spec/todo.rb", "example/app/todo/start.rb", "example/app/todo/view/index.xhtml", "example/app/whywiki_erb/layout/wiki.html.erb", "example/app/whywiki_erb/spec/wiki.rb", "example/app/whywiki_erb/start.rb", "example/app/whywiki_erb/view/edit.erb", "example/app/whywiki_erb/view/index.erb", "example/custom_middleware.rb", "example/hello.rb", "example/howto_spec.rb", "example/link.rb", "example/provides.rb", "example/session.rb", "innate.gemspec", "lib/innate.rb", "lib/innate/action.rb", "lib/innate/adapter.rb", "lib/innate/cache.rb", "lib/innate/cache/api.rb", "lib/innate/cache/drb.rb", "lib/innate/cache/file_based.rb", "lib/innate/cache/marshal.rb", "lib/innate/cache/memory.rb", "lib/innate/cache/yaml.rb", "lib/innate/current.rb", "lib/innate/default_middleware.rb", "lib/innate/dynamap.rb", "lib/innate/helper.rb", "lib/innate/helper/aspect.rb", "lib/innate/helper/cgi.rb", "lib/innate/helper/flash.rb", "lib/innate/helper/link.rb", "lib/innate/helper/redirect.rb", "lib/innate/helper/render.rb", "lib/innate/log.rb", "lib/innate/log/color_formatter.rb", "lib/innate/log/hub.rb", "lib/innate/lru_hash.rb", "lib/innate/mock.rb", "lib/innate/node.rb", "lib/innate/options.rb", "lib/innate/options/dsl.rb", "lib/innate/options/stub.rb", "lib/innate/request.rb", "lib/innate/response.rb", "lib/innate/route.rb", "lib/innate/session.rb", "lib/innate/session/flash.rb", "lib/innate/spec.rb", "lib/innate/spec/bacon.rb", "lib/innate/state.rb", "lib/innate/state/accessor.rb", "lib/innate/traited.rb", "lib/innate/trinity.rb", "lib/innate/version.rb", "lib/innate/view.rb", "lib/innate/view/erb.rb", "lib/innate/view/etanni.rb", "lib/innate/view/none.rb", "spec/example/app/retro_games.rb", "spec/example/hello.rb", "spec/example/link.rb", "spec/example/provides.rb", "spec/example/session.rb", "spec/helper.rb", "spec/innate/action/layout.rb", "spec/innate/action/layout/file_layout.xhtml", "spec/innate/cache/common.rb", "spec/innate/cache/marshal.rb", "spec/innate/cache/memory.rb", "spec/innate/cache/yaml.rb", "spec/innate/dynamap.rb", "spec/innate/etanni.rb", "spec/innate/helper.rb", "spec/innate/helper/aspect.rb", "spec/innate/helper/cgi.rb", "spec/innate/helper/flash.rb", "spec/innate/helper/link.rb", "spec/innate/helper/redirect.rb", "spec/innate/helper/render.rb", "spec/innate/helper/view/aspect_hello.xhtml", "spec/innate/helper/view/locals.xhtml", "spec/innate/helper/view/loop.xhtml", "spec/innate/helper/view/num.xhtml", "spec/innate/helper/view/partial.xhtml", "spec/innate/helper/view/recursive.xhtml", "spec/innate/mock.rb", "spec/innate/modes.rb", "spec/innate/node/mapping.rb", "spec/innate/node/node.rb", "spec/innate/node/resolve.rb", "spec/innate/node/view/another_layout/another_layout.xhtml", "spec/innate/node/view/bar.xhtml", "spec/innate/node/view/cat2/cat22.xhtml", "spec/innate/node/view/cat3/cat33.xhtml", "spec/innate/node/view/foo.html.xhtml", "spec/innate/node/view/only_view.xhtml", "spec/innate/node/view/sub/baz.xhtml", "spec/innate/node/view/sub/foo/baz.xhtml", "spec/innate/node/view/with_layout.xhtml", "spec/innate/node/wrap_action_call.rb", "spec/innate/options.rb", "spec/innate/parameter.rb", "spec/innate/provides.rb", "spec/innate/provides/list.html.xhtml", "spec/innate/provides/list.txt.xhtml", "spec/innate/request.rb", "spec/innate/response.rb", "spec/innate/route.rb", "spec/innate/session.rb", "spec/innate/traited.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/gem.rake", "tasks/gem_setup.rake", "tasks/grancher.rake", "tasks/manifest.rake", "tasks/rcov.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/ycov.rake"]
@@ -194,8 +194,8 @@ module Innate
194
194
  def recompile_middleware(mode = options[:mode])
195
195
  mode = mode.to_sym
196
196
 
197
- if MIDDLEWARE[mode]
198
- Innate.app = Rack::Builder.new(&MIDDLEWARE[mode])
197
+ if MIDDLEWARE[mode] and options[:mode] == mode
198
+ Innate.app = Rack::Builder.new(&MIDDLEWARE[mode]).to_app
199
199
  end
200
200
  end
201
201
 
@@ -238,7 +238,7 @@ module Innate
238
238
  def middleware(mode, &block)
239
239
  MIDDLEWARE[mode.to_sym] = block
240
240
 
241
- recompile_middleware
241
+ recompile_middleware(mode)
242
242
  end
243
243
 
244
244
  # @example Innate can be started by:
@@ -48,7 +48,11 @@ module Innate
48
48
  # Consider objects that have Aspect included
49
49
  def self.ancestral_aop(from)
50
50
  aop = {}
51
- from.ancestors.reverse.map { |anc| aop.merge!(AOP[anc]) if anc < Aspect }
51
+
52
+ from.ancestors.reverse.each do |anc|
53
+ aop.merge!(AOP[anc]) if anc < Aspect
54
+ end
55
+
52
56
  aop
53
57
  end
54
58
 
@@ -80,9 +80,9 @@ module Innate
80
80
  when URI
81
81
  href = first.to_s
82
82
  when /^\w+:\/\//
83
- uri = URI(first)
84
- uri.query = Rack::Utils.escape_html(uri.query)
85
- href = uri.to_s
83
+ uri = URI(first)
84
+ uri.query = Rack::Utils.escape_html(uri.query) if uri.query
85
+ href = uri.to_s
86
86
  else
87
87
  href = args.empty? ? r(text) : r(*args)
88
88
  end
@@ -31,8 +31,9 @@ module Innate
31
31
  # @see Mock.session
32
32
  # @author manveru
33
33
  def render_full(path, query = {})
34
- uri = URI(path.to_s)
34
+ uri = URI(path.to_s)
35
35
  uri.query = Rack::Utils.build_query(query)
36
+ saved = request, response, session, actions
36
37
 
37
38
  if cookie = request.env['HTTP_COOKIE']
38
39
  Mock.session do |mock|
@@ -42,6 +43,8 @@ module Innate
42
43
  else
43
44
  Mock.get(uri.to_s).body
44
45
  end
46
+ ensure
47
+ self.request, self.response, self.session, self.actions = saved
45
48
  end
46
49
 
47
50
  # Renders an action without any layout.
@@ -76,7 +79,7 @@ module Innate
76
79
  end
77
80
 
78
81
  # Renders an action view and does not execute any methods.
79
- # The rendered view will not be wrapped in a layout and instead
82
+ # The rendered view will not be wrapped in a layout and instead
80
83
  # will use the layout of the current action.
81
84
  # You can further tweak the action to be rendered by passing a block.
82
85
  #
@@ -15,8 +15,7 @@ module Innate
15
15
  # Copyright (c) 2009 Michael Fellinger <manveru@rubyists.com>
16
16
  #
17
17
  # You may redistribute it and/or modify it under the same terms as Ruby.
18
- class LRUHash < Struct.new(:max_count, :expiration,
19
- :hook, :objs, :list, :hits, :misses)
18
+ class LRUHash < Struct.new(:max_count, :expiration, :hook, :objs, :list)
20
19
  CacheObject = Struct.new(:content, :size, :atime)
21
20
 
22
21
  # On 1.8 we raise IndexError, on 1.9 we raise KeyError
@@ -25,17 +24,11 @@ module Innate
25
24
  include Enumerable
26
25
 
27
26
  def initialize(options = {}, &hook)
28
- self.max_count = options[:max_count]
27
+ self.max_count = options[:max_count]
29
28
  self.expiration = options[:expiration]
30
-
31
- avoid_insane_options
32
-
33
29
  self.hook = hook
34
-
35
30
  self.objs = {}
36
31
  self.list = []
37
-
38
- self.hits = self.misses = 0
39
32
  end
40
33
 
41
34
  def delete(key)
@@ -70,10 +63,7 @@ module Innate
70
63
  def [](key)
71
64
  expire
72
65
 
73
- unless objs.key?(key)
74
- self.misses += 1
75
- return
76
- end
66
+ return unless objs.key?(key)
77
67
 
78
68
  obj = objs[key]
79
69
  obj.atime = Time.now.to_i
@@ -81,7 +71,6 @@ module Innate
81
71
  list.delete_if{|list_key| key == list_key }
82
72
  list << key
83
73
 
84
- self.hits += 1
85
74
  obj.content
86
75
  end
87
76
 
@@ -97,17 +86,5 @@ module Innate
97
86
 
98
87
  obj
99
88
  end
100
-
101
- private
102
-
103
- # Sanity checks.
104
- def avoid_insane_options
105
- if max_count && max_count <= 0
106
- raise ArgumentError, "invalid max_count `#{max_count}'"
107
- end
108
- if expiration && expiration <= 0
109
- raise ArgumentError, "invalid expiration `#{expiration}'"
110
- end
111
- end
112
89
  end
113
90
  end
@@ -49,8 +49,14 @@ module Innate
49
49
  trait :provide => {}
50
50
  trait :fast_mappings => false
51
51
 
52
+ # Caching related traits.
53
+ trait :cache_provides => false
54
+ trait :provides_cache => LRUHash.new(:max_count => 100)
55
+
56
+ trait :cache_method_arities => false
57
+ trait :method_arity_cache => LRUHash.new(:max_count => 100)
58
+
52
59
  # @see wrap_action_call
53
- trait :action_cache => LRUHash.new
54
60
  trait :wrap => SortedSet.new
55
61
  trait :provide_set => false
56
62
  trait :needs_method => false
@@ -235,8 +241,26 @@ module Innate
235
241
  trait("#{format}_content_type" => content_type) if content_type
236
242
  end
237
243
 
244
+ ##
245
+ # Returns the list of provide handlers. This list is cached after the first
246
+ # call to this method.
247
+ #
248
+ # @return [Hash]
249
+ #
238
250
  def provides
239
- ancestral_trait.reject{|key, value| key !~ /_handler$/ }
251
+ if ancestral_trait[:cache_provides]
252
+ return ancestral_trait[:provides_cache][self] ||= provide_handlers
253
+ else
254
+ return provide_handlers
255
+ end
256
+ end
257
+
258
+ ##
259
+ # @see Innate::Node#provides
260
+ # @return [Hash]
261
+ #
262
+ def provide_handlers
263
+ ancestral_trait.reject { |key, value| key !~ /_handler$/ }
240
264
  end
241
265
 
242
266
  # This makes the Node a valid application for Rack.
@@ -285,7 +309,7 @@ module Innate
285
309
  # @see Node#resolve Node#action_found Node#action_missing
286
310
  # @author manveru
287
311
  def try_resolve(path)
288
- action = ancestral_trait[:action_cache][[self, path]] ||= resolve(path)
312
+ action = resolve(path)
289
313
  action ? action_found(action) : action_missing(path)
290
314
  end
291
315
 
@@ -372,8 +396,18 @@ module Innate
372
396
  def resolve(path, options = {})
373
397
  name, wish, engine = find_provide(path)
374
398
  node = (respond_to?(:ancestors) && respond_to?(:new)) ? self : self.class
375
- action = Action.create(:node => node, :wish => wish, :engine => engine, :path => path, :options => options)
376
- action.options.key?(:needs_method) || action.options[:needs_method] = node.needs_method?
399
+
400
+ action = Action.create(
401
+ :node => node,
402
+ :wish => wish,
403
+ :engine => engine,
404
+ :path => path,
405
+ :options => options
406
+ )
407
+
408
+ if !action.options.key?(:needs_method)
409
+ action.options[:needs_method] = node.needs_method?
410
+ end
377
411
 
378
412
  if content_type = node.ancestral_trait["#{wish}_content_type"]
379
413
  action.options[:content_type] = content_type
@@ -531,6 +565,11 @@ module Innate
531
565
  # @see Node#resolve
532
566
  # @return [Hash] mapping the name of the methods to their arity
533
567
  def update_method_arities
568
+ if ancestral_trait[:cache_method_arities] \
569
+ and ancestral_trait[:method_arity_cache][self]
570
+ return ancestral_trait[:method_arity_cache][self]
571
+ end
572
+
534
573
  @method_arities = {}
535
574
 
536
575
  exposed = ancestors & Helper::EXPOSE.to_a
@@ -542,6 +581,10 @@ module Innate
542
581
  end
543
582
  end
544
583
 
584
+ if ancestral_trait[:cache_method_arities]
585
+ ancestral_trait[:method_arity_cache][self] = @method_arities
586
+ end
587
+
545
588
  @method_arities
546
589
  end
547
590
 
@@ -1,3 +1,3 @@
1
1
  module Innate
2
- VERSION = "2012.12"
2
+ VERSION = "2013.02"
3
3
  end
@@ -37,6 +37,25 @@ class AspectDerivedWithLayout < AspectAllSpec
37
37
  end
38
38
  end
39
39
 
40
+ class AspectBeforeAllCache
41
+ Innate.node('/cached', self)
42
+ layout :layout
43
+
44
+ def self.numbers
45
+ @numbers ||= []
46
+ end
47
+
48
+ before_all do
49
+ self.class.numbers << 10
50
+ end
51
+
52
+ def index; end
53
+
54
+ def layout
55
+ return '#{@content}'
56
+ end
57
+ end
58
+
40
59
  class AspecNoMethodSpec
41
60
  Innate.node('/without_method', self)
42
61
  include Innate::Node
@@ -96,4 +115,11 @@ describe Innate::Helper::Aspect do
96
115
  $aspect_spec_before_all.should == 84
97
116
  $aspect_spec_after_all.should == 80
98
117
  end
118
+
119
+ it 'should not cache aspect blocks' do
120
+ get('/cached')
121
+ get('/cached')
122
+
123
+ AspectBeforeAllCache.numbers.should == [10, 10]
124
+ end
99
125
  end
@@ -110,6 +110,10 @@ describe Innate::Helper::Link do
110
110
  One.anchor('<blink> & <a>', :foo).
111
111
  should == '<a href="/foo">&lt;blink&gt; &amp; &lt;a&gt;</a>'
112
112
  end
113
+
114
+ should 'not append a ? when there is no query string' do
115
+ One.anchor('http://google.com').include?('?').should == false
116
+ end
113
117
  end
114
118
 
115
119
  describe 'combining #anchor and #route' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: innate
3
3
  version: !ruby/object:Gem::Version
4
- version: '2012.12'
4
+ version: '2013.02'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack