innate 2012.03 → 2012.12
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/.travis.yml +0 -1
- data/AUTHORS +2 -2
- data/CHANGELOG +996 -887
- data/MANIFEST +2 -2
- data/example/custom_middleware.rb +12 -8
- data/innate.gemspec +7 -7
- data/lib/innate.rb +90 -88
- data/lib/innate/action.rb +4 -5
- data/lib/innate/default_middleware.rb +22 -0
- data/lib/innate/helper/aspect.rb +185 -22
- data/lib/innate/lru_hash.rb +113 -0
- data/lib/innate/node.rb +13 -8
- data/lib/innate/options.rb +2 -5
- data/lib/innate/spec/bacon.rb +6 -8
- data/lib/innate/version.rb +1 -1
- data/lib/innate/view/erb.rb +1 -2
- data/lib/innate/view/etanni.rb +1 -2
- data/spec/innate/helper/flash.rb +1 -1
- metadata +56 -76
- data/lib/innate/middleware_compiler.rb +0 -66
- data/lib/innate/rack_file_wrapper.rb +0 -24
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
module Innate
|
|
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
|
+
#
|
|
14
|
+
# Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org>
|
|
15
|
+
# Copyright (c) 2009 Michael Fellinger <manveru@rubyists.com>
|
|
16
|
+
#
|
|
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)
|
|
20
|
+
CacheObject = Struct.new(:content, :size, :atime)
|
|
21
|
+
|
|
22
|
+
# On 1.8 we raise IndexError, on 1.9 we raise KeyError
|
|
23
|
+
KeyError = Module.const_defined?(:KeyError) ? KeyError : IndexError
|
|
24
|
+
|
|
25
|
+
include Enumerable
|
|
26
|
+
|
|
27
|
+
def initialize(options = {}, &hook)
|
|
28
|
+
self.max_count = options[:max_count]
|
|
29
|
+
self.expiration = options[:expiration]
|
|
30
|
+
|
|
31
|
+
avoid_insane_options
|
|
32
|
+
|
|
33
|
+
self.hook = hook
|
|
34
|
+
|
|
35
|
+
self.objs = {}
|
|
36
|
+
self.list = []
|
|
37
|
+
|
|
38
|
+
self.hits = self.misses = 0
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def delete(key)
|
|
42
|
+
return unless objs.key?(key)
|
|
43
|
+
obj = objs[key]
|
|
44
|
+
|
|
45
|
+
hook.call(key, obj.content) if hook
|
|
46
|
+
objs.delete key
|
|
47
|
+
|
|
48
|
+
list.delete_if{|list_key| key == list_key }
|
|
49
|
+
|
|
50
|
+
obj.content
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clear
|
|
54
|
+
objs.each{|key, obj| hook.call(key, obj) } if hook
|
|
55
|
+
objs.clear
|
|
56
|
+
list.clear
|
|
57
|
+
end
|
|
58
|
+
alias invalidate_all clear
|
|
59
|
+
|
|
60
|
+
def expire
|
|
61
|
+
return unless expiration
|
|
62
|
+
now = Time.now.to_i
|
|
63
|
+
|
|
64
|
+
list.each_with_index do |key, index|
|
|
65
|
+
break unless (objs[key].atime + expiration) <= now
|
|
66
|
+
delete key
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def [](key)
|
|
71
|
+
expire
|
|
72
|
+
|
|
73
|
+
unless objs.key?(key)
|
|
74
|
+
self.misses += 1
|
|
75
|
+
return
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
obj = objs[key]
|
|
79
|
+
obj.atime = Time.now.to_i
|
|
80
|
+
|
|
81
|
+
list.delete_if{|list_key| key == list_key }
|
|
82
|
+
list << key
|
|
83
|
+
|
|
84
|
+
self.hits += 1
|
|
85
|
+
obj.content
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def []=(key, obj)
|
|
89
|
+
expire
|
|
90
|
+
|
|
91
|
+
delete key if objs.key?(key)
|
|
92
|
+
|
|
93
|
+
delete list.first if max_count && max_count == list.size
|
|
94
|
+
|
|
95
|
+
objs[key] = CacheObject.new(obj, size, Time.now.to_i)
|
|
96
|
+
list << key
|
|
97
|
+
|
|
98
|
+
obj
|
|
99
|
+
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
|
+
end
|
|
113
|
+
end
|
data/lib/innate/node.rb
CHANGED
|
@@ -50,6 +50,7 @@ module Innate
|
|
|
50
50
|
trait :fast_mappings => false
|
|
51
51
|
|
|
52
52
|
# @see wrap_action_call
|
|
53
|
+
trait :action_cache => LRUHash.new
|
|
53
54
|
trait :wrap => SortedSet.new
|
|
54
55
|
trait :provide_set => false
|
|
55
56
|
trait :needs_method => false
|
|
@@ -209,6 +210,11 @@ module Innate
|
|
|
209
210
|
# @see View::get Node#provides
|
|
210
211
|
# @author manveru
|
|
211
212
|
#
|
|
213
|
+
# @note
|
|
214
|
+
# If you specify a block when calling this method you'll have to take care
|
|
215
|
+
# of rendering views and the like yourself. If you merely want to set a
|
|
216
|
+
# extension and content type you can omit the block.
|
|
217
|
+
#
|
|
212
218
|
# @todo
|
|
213
219
|
# The comment of this method may be too short for the effects it has on
|
|
214
220
|
# the rest of Innate, if you feel something is missing please let me
|
|
@@ -279,7 +285,7 @@ module Innate
|
|
|
279
285
|
# @see Node#resolve Node#action_found Node#action_missing
|
|
280
286
|
# @author manveru
|
|
281
287
|
def try_resolve(path)
|
|
282
|
-
action = resolve(path)
|
|
288
|
+
action = ancestral_trait[:action_cache][[self, path]] ||= resolve(path)
|
|
283
289
|
action ? action_found(action) : action_missing(path)
|
|
284
290
|
end
|
|
285
291
|
|
|
@@ -370,7 +376,7 @@ module Innate
|
|
|
370
376
|
action.options.key?(:needs_method) || action.options[:needs_method] = node.needs_method?
|
|
371
377
|
|
|
372
378
|
if content_type = node.ancestral_trait["#{wish}_content_type"]
|
|
373
|
-
action.options
|
|
379
|
+
action.options[:content_type] = content_type
|
|
374
380
|
end
|
|
375
381
|
|
|
376
382
|
node.update_method_arities
|
|
@@ -408,8 +414,6 @@ module Innate
|
|
|
408
414
|
# of the client.
|
|
409
415
|
#
|
|
410
416
|
# @param [String] given_name the name extracted from REQUEST_PATH
|
|
411
|
-
# @param [String] wish
|
|
412
|
-
#
|
|
413
417
|
# @return [Action, nil]
|
|
414
418
|
#
|
|
415
419
|
# @api internal
|
|
@@ -666,7 +670,8 @@ module Innate
|
|
|
666
670
|
# wish == 'html'
|
|
667
671
|
# end
|
|
668
672
|
#
|
|
669
|
-
# @param [String, #to_s]
|
|
673
|
+
# @param [String, #to_s] layout_name basename without extension of the
|
|
674
|
+
# layout to use
|
|
670
675
|
# @param [Proc, #call] block called on every dispatch if no name given
|
|
671
676
|
#
|
|
672
677
|
# @return [Proc, String] The assigned name or block
|
|
@@ -805,7 +810,7 @@ module Innate
|
|
|
805
810
|
|
|
806
811
|
def update_view_mappings
|
|
807
812
|
if ancestral_trait[:fast_mappings]
|
|
808
|
-
return @view_templates if
|
|
813
|
+
return @view_templates if @view_templates
|
|
809
814
|
end
|
|
810
815
|
|
|
811
816
|
paths = possible_paths_for(view_mappings)
|
|
@@ -814,7 +819,7 @@ module Innate
|
|
|
814
819
|
|
|
815
820
|
def update_layout_mappings
|
|
816
821
|
if ancestral_trait[:fast_mappings]
|
|
817
|
-
return @layout_templates if
|
|
822
|
+
return @layout_templates if @layout_templates
|
|
818
823
|
end
|
|
819
824
|
|
|
820
825
|
paths = possible_paths_for(layout_mappings)
|
|
@@ -854,7 +859,7 @@ module Innate
|
|
|
854
859
|
# Answer with an array of possible paths in order of significance for
|
|
855
860
|
# template lookup of the given +mappings+.
|
|
856
861
|
#
|
|
857
|
-
# @param [#map] An array two Arrays of inner and outer directories.
|
|
862
|
+
# @param [#map] mappings An array two Arrays of inner and outer directories.
|
|
858
863
|
#
|
|
859
864
|
# @return [Array]
|
|
860
865
|
# @see update_view_mappings update_layout_mappings update_template_mappings
|
data/lib/innate/options.rb
CHANGED
|
@@ -6,14 +6,11 @@ module Innate
|
|
|
6
6
|
:started, false
|
|
7
7
|
|
|
8
8
|
o "Will send ::setup to each element during Innate::start",
|
|
9
|
-
:setup, [Innate::Cache, Innate::Node]
|
|
9
|
+
:setup, [Innate, Innate::Cache, Innate::Node]
|
|
10
10
|
|
|
11
11
|
o "Trap this signal to issue shutdown, nil/false to disable trap",
|
|
12
12
|
:trap, 'SIGINT'
|
|
13
13
|
|
|
14
|
-
o "The compiler for middleware",
|
|
15
|
-
:middleware_compiler, Innate::MiddlewareCompiler
|
|
16
|
-
|
|
17
14
|
o "Indicates which default middleware to use, (:dev|:live)",
|
|
18
15
|
:mode, :dev
|
|
19
16
|
|
|
@@ -32,6 +29,6 @@ module Innate
|
|
|
32
29
|
o "Prefix used to create relative links",
|
|
33
30
|
:prefix, '/'
|
|
34
31
|
|
|
35
|
-
trigger(:mode){|value| Innate.
|
|
32
|
+
trigger(:mode){|value| Innate.recompile_middleware(value) }
|
|
36
33
|
end
|
|
37
34
|
end
|
data/lib/innate/spec/bacon.rb
CHANGED
|
@@ -4,18 +4,16 @@ require File.expand_path('../../', __FILE__) unless defined?(Innate)
|
|
|
4
4
|
|
|
5
5
|
Bacon.summary_on_exit
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
# minimal middleware, no exception handling
|
|
9
|
-
middleware(:spec){|mw| mw.innate }
|
|
7
|
+
ENV['RACK_ENV'] = 'TEST'
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
Innate.middleware(:spec) { run Innate.core }
|
|
10
|
+
|
|
11
|
+
Innate.options.started = true
|
|
12
|
+
Innate.options.mode = :spec
|
|
15
13
|
|
|
16
14
|
shared :rack_test do
|
|
17
15
|
Innate.setup_dependencies
|
|
18
16
|
extend Rack::Test::Methods
|
|
19
17
|
|
|
20
|
-
def app; Innate
|
|
18
|
+
def app; Innate; end
|
|
21
19
|
end
|
data/lib/innate/version.rb
CHANGED
data/lib/innate/view/erb.rb
CHANGED
|
@@ -6,8 +6,7 @@ module Innate
|
|
|
6
6
|
def self.call(action, string)
|
|
7
7
|
erb = View.compile(string){|str| ::ERB.new(str, nil, '%<>') }
|
|
8
8
|
erb.filename = (action.view || action.method).to_s
|
|
9
|
-
|
|
10
|
-
return html, Response.mime_type
|
|
9
|
+
erb.result(action.binding)
|
|
11
10
|
end
|
|
12
11
|
end
|
|
13
12
|
end
|
data/lib/innate/view/etanni.rb
CHANGED
data/spec/innate/helper/flash.rb
CHANGED
|
@@ -103,7 +103,7 @@ describe Innate::Helper::Flash do
|
|
|
103
103
|
|
|
104
104
|
should 'inspect combined' do
|
|
105
105
|
get('/welcome')
|
|
106
|
-
get('/inspect').body.should == {:name => 'manveru', :yes => :yeah}
|
|
106
|
+
eval(get('/inspect').body).should == {:name => 'manveru', :yes => :yeah}
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
should 'iterate over combined' do
|
metadata
CHANGED
|
@@ -1,78 +1,70 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: innate
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '2012.12'
|
|
5
5
|
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 2012
|
|
8
|
-
- 3
|
|
9
|
-
version: "2012.03"
|
|
10
6
|
platform: ruby
|
|
11
|
-
authors:
|
|
7
|
+
authors:
|
|
12
8
|
- Michael 'manveru' Fellinger
|
|
13
9
|
autorequire:
|
|
14
10
|
bindir: bin
|
|
15
11
|
cert_chain: []
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- !ruby/object:Gem::Dependency
|
|
12
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
20
15
|
name: rack
|
|
21
|
-
|
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
23
17
|
none: false
|
|
24
|
-
requirements:
|
|
18
|
+
requirements:
|
|
25
19
|
- - ~>
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
hash: 5
|
|
28
|
-
segments:
|
|
29
|
-
- 1
|
|
30
|
-
- 4
|
|
31
|
-
- 1
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
32
21
|
version: 1.4.1
|
|
33
22
|
type: :runtime
|
|
34
|
-
version_requirements: *id001
|
|
35
|
-
- !ruby/object:Gem::Dependency
|
|
36
|
-
name: rack-test
|
|
37
23
|
prerelease: false
|
|
38
|
-
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
25
|
none: false
|
|
40
|
-
requirements:
|
|
41
|
-
- -
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- 0
|
|
46
|
-
- 6
|
|
47
|
-
- 1
|
|
48
|
-
version: 0.6.1
|
|
49
|
-
type: :development
|
|
50
|
-
version_requirements: *id002
|
|
51
|
-
- !ruby/object:Gem::Dependency
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 1.4.1
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
52
31
|
name: bacon
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 1.1.0
|
|
38
|
+
type: :development
|
|
53
39
|
prerelease: false
|
|
54
|
-
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
55
41
|
none: false
|
|
56
|
-
requirements:
|
|
57
|
-
- -
|
|
58
|
-
- !ruby/object:Gem::Version
|
|
59
|
-
hash: 19
|
|
60
|
-
segments:
|
|
61
|
-
- 1
|
|
62
|
-
- 1
|
|
63
|
-
- 0
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
64
45
|
version: 1.1.0
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rack-test
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 0.6.1
|
|
65
54
|
type: :development
|
|
66
|
-
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.6.1
|
|
67
62
|
description: Simple, straight-forward base for web-frameworks.
|
|
68
63
|
email: m.fellinger@gmail.com
|
|
69
64
|
executables: []
|
|
70
|
-
|
|
71
65
|
extensions: []
|
|
72
|
-
|
|
73
66
|
extra_rdoc_files: []
|
|
74
|
-
|
|
75
|
-
files:
|
|
67
|
+
files:
|
|
76
68
|
- .gems
|
|
77
69
|
- .gitignore
|
|
78
70
|
- .load_gemset
|
|
@@ -112,6 +104,7 @@ files:
|
|
|
112
104
|
- lib/innate/cache/memory.rb
|
|
113
105
|
- lib/innate/cache/yaml.rb
|
|
114
106
|
- lib/innate/current.rb
|
|
107
|
+
- lib/innate/default_middleware.rb
|
|
115
108
|
- lib/innate/dynamap.rb
|
|
116
109
|
- lib/innate/helper.rb
|
|
117
110
|
- lib/innate/helper/aspect.rb
|
|
@@ -123,13 +116,12 @@ files:
|
|
|
123
116
|
- lib/innate/log.rb
|
|
124
117
|
- lib/innate/log/color_formatter.rb
|
|
125
118
|
- lib/innate/log/hub.rb
|
|
126
|
-
- lib/innate/
|
|
119
|
+
- lib/innate/lru_hash.rb
|
|
127
120
|
- lib/innate/mock.rb
|
|
128
121
|
- lib/innate/node.rb
|
|
129
122
|
- lib/innate/options.rb
|
|
130
123
|
- lib/innate/options/dsl.rb
|
|
131
124
|
- lib/innate/options/stub.rb
|
|
132
|
-
- lib/innate/rack_file_wrapper.rb
|
|
133
125
|
- lib/innate/request.rb
|
|
134
126
|
- lib/innate/response.rb
|
|
135
127
|
- lib/innate/route.rb
|
|
@@ -212,38 +204,26 @@ files:
|
|
|
212
204
|
- tasks/ycov.rake
|
|
213
205
|
homepage: http://github.com/manveru/innate
|
|
214
206
|
licenses: []
|
|
215
|
-
|
|
216
207
|
post_install_message:
|
|
217
208
|
rdoc_options: []
|
|
218
|
-
|
|
219
|
-
require_paths:
|
|
209
|
+
require_paths:
|
|
220
210
|
- lib
|
|
221
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
222
212
|
none: false
|
|
223
|
-
requirements:
|
|
224
|
-
- -
|
|
225
|
-
- !ruby/object:Gem::Version
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
- 0
|
|
229
|
-
version: "0"
|
|
230
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
|
+
requirements:
|
|
214
|
+
- - ! '>='
|
|
215
|
+
- !ruby/object:Gem::Version
|
|
216
|
+
version: '0'
|
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
218
|
none: false
|
|
232
|
-
requirements:
|
|
233
|
-
- -
|
|
234
|
-
- !ruby/object:Gem::Version
|
|
235
|
-
hash: 25
|
|
236
|
-
segments:
|
|
237
|
-
- 1
|
|
238
|
-
- 3
|
|
239
|
-
- 1
|
|
219
|
+
requirements:
|
|
220
|
+
- - ! '>='
|
|
221
|
+
- !ruby/object:Gem::Version
|
|
240
222
|
version: 1.3.1
|
|
241
223
|
requirements: []
|
|
242
|
-
|
|
243
224
|
rubyforge_project: innate
|
|
244
|
-
rubygems_version: 1.8.
|
|
225
|
+
rubygems_version: 1.8.24
|
|
245
226
|
signing_key:
|
|
246
227
|
specification_version: 3
|
|
247
228
|
summary: Powerful web-framework wrapper for Rack.
|
|
248
229
|
test_files: []
|
|
249
|
-
|