renee-core 0.4.0.pre1 → 0.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renee-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre1
4
+ version: 0.4.0.pre2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,33 +11,33 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-01-23 00:00:00.000000000Z
14
+ date: 2012-03-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
18
- requirement: &70111991759760 !ruby/object:Gem::Requirement
18
+ requirement: &70163827844980 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ! '>='
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.3.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70111991759760
26
+ version_requirements: *70163827844980
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
- requirement: &70111991759260 !ruby/object:Gem::Requirement
29
+ requirement: &70163827844260 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: 2.6.1
34
+ version: 2.11.1
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *70111991759260
37
+ version_requirements: *70163827844260
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: bundler
40
- requirement: &70111991758860 !ruby/object:Gem::Requirement
40
+ requirement: &70163827843620 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70111991758860
48
+ version_requirements: *70163827843620
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rack-test
51
- requirement: &70111991758280 !ruby/object:Gem::Requirement
51
+ requirement: &70163827842000 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 0.5.0
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70111991758280
59
+ version_requirements: *70163827842000
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rake
62
- requirement: &70111991757700 !ruby/object:Gem::Requirement
62
+ requirement: &70163827841320 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70111991757700
70
+ version_requirements: *70163827841320
71
71
  description: The super-friendly rack helpers.
72
72
  email:
73
73
  - joshbuddy@gmail.com
@@ -77,27 +77,29 @@ executables: []
77
77
  extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
+ - .gitignore
81
+ - .travis.yml
82
+ - Gemfile
83
+ - MIT-LICENSE.txt
84
+ - README.md
85
+ - Rakefile
80
86
  - lib/renee/core.rb
81
87
  - lib/renee/core/chaining.rb
82
- - lib/renee/core/env_accessors.rb
83
88
  - lib/renee/core/exceptions.rb
84
- - lib/renee/core/matcher.rb
85
89
  - lib/renee/core/plugins.rb
86
90
  - lib/renee/core/rack_interaction.rb
87
- - lib/renee/core/request_context.rb
88
91
  - lib/renee/core/responding.rb
89
- - lib/renee/core/response.rb
90
92
  - lib/renee/core/routing.rb
91
93
  - lib/renee/core/transform.rb
92
- - test/renee-core/chaining_test.rb
93
- - test/renee-core/env_accessors_test.rb
94
- - test/renee-core/include_test.rb
95
- - test/renee-core/request_context_test.rb
96
- - test/renee-core/responding_test.rb
97
- - test/renee-core/routing_test.rb
98
- - test/renee-core/test_helper.rb
99
- - test/renee-core/variable_type_test.rb
94
+ - lib/renee/core/version.rb
95
+ - renee-core.gemspec
96
+ - test/chaining_test.rb
97
+ - test/include_test.rb
98
+ - test/request_context_test.rb
99
+ - test/responding_test.rb
100
+ - test/routing_test.rb
100
101
  - test/test_helper.rb
102
+ - test/variable_type_test.rb
101
103
  homepage: http://reneerb.com
102
104
  licenses: []
103
105
  post_install_message:
@@ -112,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
114
  version: '0'
113
115
  segments:
114
116
  - 0
115
- hash: -4060874974939787425
117
+ hash: 1919719039432149420
116
118
  required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  none: false
118
120
  requirements:
@@ -126,13 +128,11 @@ signing_key:
126
128
  specification_version: 3
127
129
  summary: The super-friendly rack helpers
128
130
  test_files:
129
- - test/renee-core/chaining_test.rb
130
- - test/renee-core/env_accessors_test.rb
131
- - test/renee-core/include_test.rb
132
- - test/renee-core/request_context_test.rb
133
- - test/renee-core/responding_test.rb
134
- - test/renee-core/routing_test.rb
135
- - test/renee-core/test_helper.rb
136
- - test/renee-core/variable_type_test.rb
131
+ - test/chaining_test.rb
132
+ - test/include_test.rb
133
+ - test/request_context_test.rb
134
+ - test/responding_test.rb
135
+ - test/routing_test.rb
137
136
  - test/test_helper.rb
137
+ - test/variable_type_test.rb
138
138
  has_rdoc:
@@ -1,72 +0,0 @@
1
- module Renee
2
- class Core
3
- # Defines class-level methods for creating accessors for variables in your environment.
4
- module EnvAccessors
5
-
6
- # Exception for attempting to define an env accessor cannot be written as a method name.
7
- # @example
8
- # env_accessor "current.user" # raises InvalidEnvNameError
9
- # env_accessor "current.user" => :current_user # this works
10
- InvalidEnvNameError = Class.new(RuntimeError)
11
-
12
- # Class-methods included by this module.
13
- module ClassMethods
14
-
15
- # Defines getters and setters for a list of attributes. If the attributes cannot easily be expressed, use the
16
- # hash-syntax for defining them.
17
- # @example
18
- # env_accessor "some_value" # will define methods to read and write env['some_value']
19
- # env_accessor "current.user" => :current_user will define methods to read and write env['current.user']
20
- def env_accessor(*attrs)
21
- env_reader(*attrs)
22
- env_writer(*attrs)
23
- end
24
-
25
- # Defines getters for a list of attributes.
26
- # @see env_accessor
27
- def env_reader(*attrs)
28
- instance_eval do
29
- env_attr_iter(*attrs) do |key, meth|
30
- define_method(meth) do
31
- env[key]
32
- end
33
- end
34
- end
35
- end
36
-
37
- # Defines setters for a list of attributes.
38
- # @see env_accessor
39
- def env_writer(*attrs)
40
- instance_eval do
41
- env_attr_iter(*attrs) do |key, meth|
42
- define_method("#{meth}=") do |val|
43
- env[key] = val
44
- end
45
- end
46
- end
47
- end
48
-
49
- private
50
- def env_attr_iter(*attrs)
51
- attrs.each do |a|
52
- case a
53
- when Hash
54
- a.each do |k, v|
55
- yield k, v
56
- end
57
- else
58
- raise InvalidEnvNameError, "Called env attr for #{a.inspect}, to use this, call your env method like this. env_reader #{a.inspect} => #{a.to_s.gsub(/-\./, '_').to_sym.inspect}" if a.to_s[/[-\.]/]
59
- yield a, a.to_sym
60
- end
61
- end
62
- end
63
-
64
- end
65
-
66
- # @private
67
- def self.included(o)
68
- o.extend(ClassMethods)
69
- end
70
- end
71
- end
72
- end
@@ -1,61 +0,0 @@
1
- module Renee
2
- class Core
3
- # Class used for variable matching.
4
- class Matcher
5
- attr_accessor :name
6
-
7
- # @param [Regexp] matcher The regexp matcher to determine what is part of the variable.
8
- def initialize(matcher)
9
- @matcher = matcher
10
- end
11
-
12
- # Used to specific the error handler if the matcher doesn't match anything. By default, there is no error handler.
13
- # @yield The block to be executed it fails to match.
14
- def on_error(&blk)
15
- @error_handler = blk
16
- self
17
- end
18
-
19
- # Used to transform the value matched.
20
- # @yield TODO
21
- def on_transform(&blk)
22
- @transform_handler = blk
23
- self
24
- end
25
-
26
- # Convienence method to creating halting error handler.
27
- # @param [Symbol, Integer] error_code The HTTP code to halt with.
28
- # @see #interpret_response
29
- def raise_on_error!(error_code = :bad_request)
30
- on_error { halt error_code }
31
- self
32
- end
33
-
34
- # Matcher for string
35
- # @param [String] val The value to attempt to match on.
36
- # @raise [ClientError] If the match fails to match and there is an error handler defined.
37
- def [](val)
38
- match = nil
39
- case @matcher
40
- when Array
41
- match = nil
42
- @matcher.find { |m| match = m[val] }
43
- else
44
- if match = /^#{@matcher.to_s}/.match(val)
45
- match = [match[0]]
46
- match << @transform_handler.call(match.first) if @transform_handler
47
- match
48
- end
49
- end
50
- if match
51
- match
52
- elsif @error_handler
53
- raise ClientError.new("There was an error interpreting the value #{val.inspect} for #{name.inspect}", &@error_handler)
54
- end
55
- end
56
- end
57
-
58
- # Matcher for Integers
59
- IntegerMatcher = Matcher.new(/\d+/).on_transform{|v| Integer(v)}
60
- end
61
- end
@@ -1,56 +0,0 @@
1
- module Renee
2
- class Core
3
- module ClassMethods
4
- def use(mw, *args, &blk)
5
- middlewares << [mw, args, blk]
6
- end
7
-
8
- def middlewares
9
- @middlewares ||= []
10
- end
11
- end
12
-
13
- # This module deals with the Rack#call compilance. It defines #call and also defines several critical methods
14
- # used by interaction by other application modules.
15
- module RequestContext
16
- attr_reader :env, :request, :detected_extension
17
-
18
- # Provides a rack interface compliant call method.
19
- # @param[Hash] env The rack environment.
20
- def call(e)
21
- initialize_plugins
22
- idx = 0
23
- next_app = proc do |env|
24
- if idx == self.class.middlewares.size
25
- @env, @request = env, Rack::Request.new(env)
26
- @detected_extension = env['PATH_INFO'][/\.([^\.\/]+)$/, 1]
27
- # TODO clear template cache in development? `template_cache.clear`
28
- out = catch(:halt) do
29
- begin
30
- self.class.before_blocks.each { |b| instance_eval(&b) }
31
- instance_eval(&self.class.application_block)
32
- rescue ClientError => e
33
- e.response ? instance_eval(&e.response) : halt("There was an error with your request", 400)
34
- rescue NotMatchedError => e
35
- # unmatched, continue on
36
- end
37
- Renee::Core::Response.new("Not found", 404).finish
38
- end
39
- self.class.after_blocks.each { |a| out = instance_exec(out, &a) }
40
- out
41
- else
42
- middleware = self.class.middlewares[idx]
43
- idx += 1
44
- middleware[0].new(next_app, *middleware[1], &middleware[2]).call(env)
45
- end
46
- end
47
- next_app[e]
48
- end # call
49
-
50
- def initialize_plugins
51
- self.class.init_blocks.each { |init_block| self.class.class_eval(&init_block) }
52
- self.class.send(:define_method, :initialize_plugins) { }
53
- end
54
- end
55
- end
56
- end
@@ -1,78 +0,0 @@
1
- module Renee
2
- class Core
3
- # The response object for a Renee request. Inherits from the `Rack#Response` object.
4
- class Response < Rack::Response
5
- # Augment body to allow strings.
6
- #
7
- # @param [String] The contents for the response.
8
- #
9
- # @example
10
- # res.body = "Hello"
11
- #
12
- # @api semipublic
13
- def body=(value)
14
- value = value.body while Rack::Response === value
15
- @body = String === value ? [value.to_str] : value
16
- end
17
-
18
- # Alias status and body methods to allow redefinition
19
- alias :status_attr :status
20
- alias :status_attr= :status=
21
- alias :body_attr :body
22
- alias :body_attr= :body=
23
-
24
- # Get or set the status of the response.
25
- #
26
- # @param [String] val The status code to return.
27
- #
28
- # @example
29
- # res.status 400
30
- # res.status => 400
31
- #
32
- # @api public
33
- def status(val=nil)
34
- val ? self.status_attr = val : self.status_attr
35
- end
36
-
37
- # Get or set the body of the response.
38
- #
39
- # @param [String] val The contents to return.
40
- #
41
- # @example
42
- # res.body "hello"
43
- # res.body => "hello"
44
- #
45
- # @api public
46
- def body(val=nil)
47
- val ? self.body_attr = val : self.body_attr
48
- end
49
-
50
- # Get or set the headers of the response.
51
- #
52
- # @param [Hash] attrs The contents to return.
53
- #
54
- # @example
55
- # res.headers :foo => "bar"
56
- # res.headers => { :foo => "bar" }
57
- #
58
- # @api public
59
- def headers(attrs={})
60
- attrs ? attrs.each { |k, v| self[k.to_s] = v } : self.header
61
- end
62
-
63
- # Finishs the response based on the accumulated options.
64
- # Calculates the size of the body content length and removes headers for 1xx status codes.
65
- def finish
66
- if status.to_i / 100 == 1
67
- headers.delete "Content-Length"
68
- headers.delete "Content-Type"
69
- elsif Array === body and not [204, 304].include?(status.to_i)
70
- headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
71
- end
72
-
73
- status, headers, result = super
74
- [status, headers, result]
75
- end
76
- end
77
- end
78
- end
@@ -1,43 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.expand_path('../test_helper', __FILE__)
4
-
5
- describe Renee::Core::EnvAccessors do
6
- it "should allow accessing the env" do
7
- @app = Renee.core {
8
- self.test = 'hello'
9
- path('test').get do
10
- halt "test is #{test}"
11
- end
12
- }.setup {
13
- env_accessor :test
14
- }
15
- get '/test'
16
- assert_equal 200, response.status
17
- assert_equal 'test is hello', response.body
18
- end
19
-
20
- it "should raise when you try to access weird env keys" do
21
- assert_raises(Renee::Core::EnvAccessors::InvalidEnvNameError) {
22
- @app = Renee.core {
23
- self.test_test = 'hello'
24
- }.setup {
25
- env_accessor "test.test"
26
- }
27
- }
28
- end
29
-
30
- it "should allow weird env keys if you map them" do
31
- @app = Renee.core {
32
- self.test_test = 'hello'
33
- path('test').get do
34
- halt "test is #{test_test}"
35
- end
36
- }.setup {
37
- env_accessor "test.test" => :test_test
38
- }
39
- get '/test'
40
- assert_equal 200, response.status
41
- assert_equal 'test is hello', response.body
42
- end
43
- end
@@ -1,4 +0,0 @@
1
- $: << File.expand_path('../../lib', __FILE__)
2
- require 'renee/core'
3
- # Load shared test helpers
4
- require File.expand_path('../../test_helper', __FILE__)