renee-core 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts CHANGED
@@ -1,4 +1,4 @@
1
- --output-dir ../doc/core
1
+ --output-dir ../../renee-site/public/doc/core
2
2
  --readme README.md
3
3
  --no-private
4
4
  --title Renee Core
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require "bundler/gem_tasks"
2
1
  require 'rake/testtask'
3
2
  require 'yard'
4
3
 
@@ -3,8 +3,18 @@ require 'set'
3
3
  class Renee
4
4
  class Core
5
5
  class Application
6
+ # Module for creating chainable methods. To use this within your own modules, first `include Chaining`, then,
7
+ # mark methods you want to be available with `chain_method :method_name`.
8
+ # @example
9
+ # module MoreRoutingMethods
10
+ # include Chaining
11
+ # def other_routing_method
12
+ # # ..
13
+ # end
14
+ # chain_method :other_routing_method
15
+ #
6
16
  module Chaining
7
- private
17
+ # @private
8
18
  class ChainingProxy
9
19
  def initialize(target, proxy_blk)
10
20
  @target, @proxy_blk, @calls = target, proxy_blk, []
@@ -34,6 +44,7 @@ class Renee
34
44
  end
35
45
  end
36
46
 
47
+ # @private
37
48
  module ClassMethods
38
49
  def chain_method(*methods)
39
50
  methods.each do |m|
@@ -12,6 +12,11 @@ class Renee
12
12
  run Rack::Builder.new(&blk).to_app
13
13
  end
14
14
 
15
+ # Creates an ad-hoc Rack application within the context of a Rack::Builder that immediately halts when done.
16
+ # @see #run!
17
+ # @example
18
+ # get { halt build { use Rack::ContentLength; run proc { |env| Rack::Response.new("Hello!").finish } } }
19
+ #
15
20
  def build!(&blk)
16
21
  run! build(&blk)
17
22
  end
@@ -25,7 +30,7 @@ class Renee
25
30
  (app || blk).call(env)
26
31
  end
27
32
 
28
- # Runs a rack application and responds immediately.
33
+ # Runs a rack application and halts immediately.
29
34
  #
30
35
  # @see #run
31
36
  # @example
@@ -54,8 +54,7 @@ class Renee
54
54
 
55
55
  # Match parts off the path as variables. The parts matcher can conform to either a regular expression, or be an Integer, or
56
56
  # simply a String.
57
- # @param[Object] type the type of object to match for. If you supply Integer, this will only match integers in addition to
58
- # casting your variable for you.
57
+ # @param[Object] type the type of object to match for. If you supply Integer, this will only match integers in addition to casting your variable for you.
59
58
  # @param[Object] default the default value to use if your param cannot be successfully matched.
60
59
  #
61
60
  # @example
@@ -83,6 +82,9 @@ class Renee
83
82
  alias_method :var, :variable
84
83
  chain_method :variable, :var
85
84
 
85
+ # Same as variable except you can match multiple variables with the same type.
86
+ # @param [Range, Integer] count The number of parameters to capture.
87
+ # @param [Symbol] type The type to use for match.
86
88
  def multi_variable(count, type = nil, &blk)
87
89
  complex_variable(type, '/', count, &blk)
88
90
  end
@@ -90,6 +92,8 @@ class Renee
90
92
  alias_method :mvar, :multi_variable
91
93
  chain_method :multi_variable, :multi_var, :mvar
92
94
 
95
+ # Same as variable except it matches indefinitely.
96
+ # @param [Symbol] type The type to use for match.
93
97
  def repeating_variable(type = nil, &blk)
94
98
  complex_variable(type, '/', nil, &blk)
95
99
  end
@@ -2,6 +2,10 @@ class Renee
2
2
  class Core
3
3
  class Application
4
4
  module Transform
5
+ # Transforms a value according to the rules specified by #register_variable_name.
6
+ # @param [Symbol] name The name of the variable type.
7
+ # @param [String] value The value to transform.
8
+ # @return The transformed value or nil.
5
9
  def transform(type, value)
6
10
  if settings.variable_types.key?(type) and m = settings.variable_types[type][value]
7
11
  m.first == value ? m.last : nil
@@ -1,8 +1,12 @@
1
1
  class Renee
2
2
  class Core
3
+ # Used to indicate a client-error has occurred (e.g. 4xx)
3
4
  class ClientError < StandardError
4
5
  attr_reader :response
5
- def initialize(message, response = nil)
6
+
7
+ # @param [String] message The message for this exception.
8
+ # @yield The optional block to instance-eval in the case this error is raised.
9
+ def initialize(message, &response)
6
10
  super(message)
7
11
  @response = response
8
12
  end
@@ -1,5 +1,6 @@
1
1
  class Renee
2
2
  class Core
3
+ # @private
3
4
  class Matcher
4
5
  attr_accessor :name
5
6
 
@@ -42,7 +43,7 @@ class Renee
42
43
  if match
43
44
  match
44
45
  elsif @error_handler
45
- raise ClientError.new("There was an error interpreting the value #{val.inspect} for #{name.inspect}", @error_handler)
46
+ raise ClientError.new("There was an error interpreting the value #{val.inspect} for #{name.inspect}", &@error_handler)
46
47
  end
47
48
  end
48
49
  end
@@ -29,10 +29,16 @@ class Renee
29
29
  path ? @views_path = path : @views_path
30
30
  end
31
31
 
32
- def include(mod)
33
- includes << mod
32
+ # Module(s) to include into the base application.
33
+ # @param [Module] mods Modules to include.
34
+ def include(*mods)
35
+ mods.each { |mod| includes << mod }
34
36
  end
35
37
 
38
+ # Registers a new variable type for use within {Renee::Application::Routing#variable} and others.
39
+ # @param [Symbol] name The name of the variable.
40
+ # @param [Regexp] matcher A regexp describing what part of an arbitrary string to capture.
41
+ # @return [Renee::Core::Matcher] A matcher
36
42
  def register_variable_type(name, matcher)
37
43
  matcher = case matcher
38
44
  when Matcher then matcher
@@ -62,7 +62,7 @@ class Renee
62
62
  generator = url_generators[name]
63
63
  generator ? generator.url(*args) : raise("Generator for #{name} doesn't exist")
64
64
  end
65
-
65
+
66
66
  private
67
67
  def url_generators
68
68
  @url_generators ||= {}
@@ -72,7 +72,6 @@ class Renee
72
72
  @generation_defaults && defaults ? @generation_defaults.merge(defaults) : (defaults || @generation_defaults)
73
73
  end
74
74
 
75
- # Manages generating paths and urls for a given name.
76
75
  # @private
77
76
  class Generator
78
77
  attr_reader :defaults
@@ -1,5 +1,6 @@
1
1
  class Renee
2
2
  class Core
3
- VERSION = "0.1.0"
3
+ # Current Renee-core version number.
4
+ VERSION = "0.1.1"
4
5
  end
5
6
  end
data/lib/renee-core.rb CHANGED
@@ -7,7 +7,7 @@ require 'renee-core/application'
7
7
  require 'renee-core/url_generation'
8
8
  require 'renee-core/exceptions'
9
9
 
10
- # Renee top-level constant
10
+ # Top-level Renee constant
11
11
  class Renee
12
12
  # The top-level class for creating core application.
13
13
  # For convience you can also used a method named #Renee
@@ -19,14 +19,18 @@ class Renee
19
19
  class Core
20
20
  include URLGeneration
21
21
 
22
- attr_reader :application_block, :settings
22
+ # The application block used to initialize this application.
23
+ attr_reader :application_block
24
+ # The {Settings} object used to initialize this application.
25
+ attr_reader :settings
23
26
 
24
27
  # @param [Proc] application_block The block of code that will be executed on each invocation of call #call.
25
28
  # Each time #call is called, a new instance of {Renee::Core::Application} will
26
29
  # be created. The block given will be #instance_eval 'd within
27
30
  # the context of that new instance.
28
31
  #
29
- def initialize(&application_block)
32
+ def initialize(base_application_class = Application, &application_block)
33
+ @base_application_class = base_application_class
30
34
  @application_block = application_block
31
35
  @settings = Settings.new
32
36
  end
@@ -40,9 +44,8 @@ class Renee
40
44
  # @see http://rack.rubyforge.org/doc/SPEC.html
41
45
  #
42
46
  def call(env)
43
- Application.new(settings, &application_block).call(env)
47
+ application_class.new(settings, &application_block).call(env)
44
48
  end
45
- alias_method :[], :call
46
49
 
47
50
  ##
48
51
  # Configure settings for your Renee application. Accepts a settings file path
@@ -62,5 +65,14 @@ class Renee
62
65
  end
63
66
  self
64
67
  end
68
+
69
+ private
70
+ def application_class
71
+ @application_class ||= begin
72
+ app_cls = Class.new(@base_application_class)
73
+ settings.includes.each { |inc| app_cls.send(:include, inc) }
74
+ app_cls
75
+ end
76
+ end
65
77
  end
66
78
  end
data/renee-core.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.version = Renee::Core::VERSION
8
8
  s.authors = ["Josh Hull", "Nathan Esquenazi", "Arthur Chiu"]
9
9
  s.email = ["joshbuddy@gmail.com", "nesquena@gmail.com", "mr.arthur.chiu@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{The super-friendly rack helpers.}
10
+ s.homepage = "http://reneerb.com"
11
+ s.summary = %q{The super-friendly rack helpers}
12
12
  s.description = %q{The super-friendly rack helpers.}
13
13
 
14
14
  s.rubyforge_project = "renee"
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ describe "Route::Settings#include" do
4
+ it "should allow the inclusion of arbitrary modules" do
5
+ type = { 'Content-Type' => 'text/plain' }
6
+ @app = Renee::Core.new {
7
+ halt :ok if respond_to?(:hi)
8
+ }.setup {
9
+ include Module.new { def hi; end }
10
+ }
11
+ get '/'
12
+ assert_equal 200, response.status
13
+ end
14
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: renee-core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Hull
@@ -84,7 +84,6 @@ files:
84
84
  - .yardopts
85
85
  - README.md
86
86
  - Rakefile
87
- - ideal.rb
88
87
  - lib/renee-core.rb
89
88
  - lib/renee-core/application.rb
90
89
  - lib/renee-core/application/chaining.rb
@@ -101,12 +100,13 @@ files:
101
100
  - lib/renee-core/version.rb
102
101
  - renee-core.gemspec
103
102
  - test/chaining_test.rb
103
+ - test/include_test.rb
104
104
  - test/responding_test.rb
105
105
  - test/routing_test.rb
106
106
  - test/test_helper.rb
107
107
  - test/url_generation_test.rb
108
108
  - test/variable_type_test.rb
109
- homepage: ""
109
+ homepage: http://reneerb.com
110
110
  licenses: []
111
111
 
112
112
  post_install_message:
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- hash: -2644091870970264113
122
+ hash: 4467242971935136938
123
123
  segments:
124
124
  - 0
125
125
  version: "0"
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- hash: -2644091870970264113
131
+ hash: 4467242971935136938
132
132
  segments:
133
133
  - 0
134
134
  version: "0"
@@ -138,9 +138,10 @@ rubyforge_project: renee
138
138
  rubygems_version: 1.8.10
139
139
  signing_key:
140
140
  specification_version: 3
141
- summary: The super-friendly rack helpers.
141
+ summary: The super-friendly rack helpers
142
142
  test_files:
143
143
  - test/chaining_test.rb
144
+ - test/include_test.rb
144
145
  - test/responding_test.rb
145
146
  - test/routing_test.rb
146
147
  - test/test_helper.rb
data/ideal.rb DELETED
@@ -1,49 +0,0 @@
1
- require 'rubygems'
2
- require 'benchmark'
3
-
4
- $: << 'lib'
5
- require 'renee'
6
-
7
- router = Renee::Core.new {
8
- path 'test/time' do
9
- query_string 'ok' do
10
- get { halt "ok" }
11
- post { halt [200, {}, ['POSTED!']] }
12
- end
13
- end
14
- variable do |id1, id2|
15
- path 'more' do
16
- get {
17
- halt [200, {}, "this is the id1: #{id1} id2: #{id2}" ]
18
- }
19
- end
20
- end
21
- remainder do |rest|
22
- halt "the rest is #{rest}"
23
- end
24
- }.setup {
25
- view_path('views')
26
- environment(:development)
27
- }
28
-
29
- app = Renee do
30
- path "add" do
31
- variable Integer do |first, second|
32
- "#{first} + #{second} = #{first + second}"
33
- end
34
- end
35
- end
36
-
37
- p router.call(Rack::MockRequest.env_for('/add/3/4')) # => "3 + 4 = 7"
38
-
39
- p router.call(Rack::MockRequest.env_for('/test/time?ok'))
40
- p router.call(Rack::MockRequest.env_for('/test/josh/more'))
41
- p router.call(Rack::MockRequest.env_for('/'))
42
-
43
-
44
- #puts Benchmark.measure {
45
- #50_000.times do
46
- # router.call(Rack::MockRequest.env_for('/test/josh/more'))
47
- #router.call(Rack::MockRequest.env_for('/test/time?ok', :method => 'POST' ))
48
- #end
49
- #}