rack-app 0.9.1 → 0.9.2

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
  SHA1:
3
- metadata.gz: 6e9e97fcff12d6ec6e33b8b73bb3a2858cfdb028
4
- data.tar.gz: d40cb38798d131f0905d31f3682b1ff500ab0421
3
+ metadata.gz: 11562e09e4e7087bbaefaeb911d0ce5a87cf80e6
4
+ data.tar.gz: deefda74befc47f77bc3c7c6f65b0420772a936a
5
5
  SHA512:
6
- metadata.gz: b8ed888abbdc3e27359e19bba5b00285ab44515d4958b0b7364f37bb1f9cdbcc92cbda0a4dbd4e110e6631cc126ef1921d1922112b8e75a553c75a08cad464b8
7
- data.tar.gz: 3e1000a744087c86caa8eccd83d2ae333f7a471adbd7271c0f6d443e341e111afca9408560f489ad4caa4f6e17162e6c992b5005d71ef7c915f255b6dbe92a22
6
+ metadata.gz: 290f0f4386397f899f4101268c12d0ccc1a7ab06d6ecb224f141915994544bfb77021b34f52eea87b109e0b67a8f7910a25c17ad15b8ca3eea6a3c60f714d6be
7
+ data.tar.gz: db9c38482271907d84fd88db8de910b228f77a2c7f7be0ee08c20584b86c6f59c8a0b74496eac020ba9feb39b89199b9f04a9f0f8c52fc2d51c4dd38a7c6ba52
data/README.md CHANGED
@@ -47,12 +47,13 @@ class YourAwesomeApp < Rack::App
47
47
  'Hello World!'
48
48
  end
49
49
 
50
- get '/users/:user_id' do
51
- get_user_id
50
+ get '/users/:user_id' do
51
+ params['user_id'] #=> restful parameter :user_id
52
+ say #=> "hello world!"
52
53
  end
53
54
 
54
- def get_user_id
55
- params['user_id']
55
+ def say
56
+ 'hello world!'
56
57
  end
57
58
 
58
59
  end
@@ -68,7 +69,7 @@ By default if you dont write anything to the response 'body' the endpoint block
68
69
 
69
70
  ## Testing
70
71
 
71
- use bundled in testing module for writing unit test for your rack application
72
+ for testing use rack/test or the bundled testing module for writing unit test for your rack application
72
73
 
73
74
  ```ruby
74
75
 
@@ -83,7 +84,7 @@ describe MyRackApp do
83
84
 
84
85
  describe '#something' do
85
86
 
86
- subject{ get('/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}) }
87
+ subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}) }
87
88
 
88
89
  it { expect(subject.body).to eq ['world']}
89
90
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
@@ -77,12 +77,15 @@ class Rack::App
77
77
  def add_route(request_method, request_path, &block)
78
78
 
79
79
  endpoint_properties = {
80
+ :user_defined_logic => block,
80
81
  :request_method => request_method,
81
82
  :request_path => request_path,
82
- :description => @last_description
83
+ :description => @last_description,
84
+ :serializer => @serializer,
85
+ :app_class => self
83
86
  }
84
87
 
85
- endpoint = Rack::App::Endpoint.new(self, endpoint_properties, &block)
88
+ endpoint = Rack::App::Endpoint.new(endpoint_properties)
86
89
  router.add_endpoint(request_method, request_path, endpoint)
87
90
 
88
91
  @last_description = nil
@@ -101,6 +104,10 @@ class Rack::App
101
104
  return nil
102
105
  end
103
106
 
107
+ def serializer(&code)
108
+ @serializer = code
109
+ end
110
+
104
111
  end
105
112
 
106
113
  def params
@@ -2,13 +2,16 @@ class Rack::App::Endpoint
2
2
 
3
3
  attr_reader :properties
4
4
 
5
- def initialize(api_class, properties={}, &logic_block)
5
+ def initialize(properties)
6
6
  @properties = properties
7
- @logic_block = logic_block
8
- @api_class = api_class
7
+ @logic_block = properties[:user_defined_logic]
8
+ @serializer = properties[:serializer] || default_serializer
9
+ @api_class = properties[:app_class]
10
+
9
11
  @path_params_matcher = {}
10
12
  end
11
13
 
14
+
12
15
  def execute(request_env)
13
16
 
14
17
  request = Rack::Request.new(request_env)
@@ -36,7 +39,7 @@ class Rack::App::Endpoint
36
39
  protected
37
40
 
38
41
  def add_response_body_if_missing(call_return, response)
39
- response.write(call_return.to_s) if response.body.empty?
42
+ response.write(String(@serializer.call(call_return))) if response.body.empty?
40
43
  end
41
44
 
42
45
  def is_a_rack_response_finish?(call_return)
@@ -46,4 +49,8 @@ class Rack::App::Endpoint
46
49
  call_return[1].is_a?(Hash)
47
50
  end
48
51
 
52
+ def default_serializer
53
+ lambda { |o| o.to_s }
54
+ end
55
+
49
56
  end
@@ -1,6 +1,15 @@
1
- api_class = Class.new(Rack::App)
2
- Rack::App::Endpoint::NOT_FOUND = Rack::App::Endpoint.new(api_class) do
3
- response.status= 404
4
- response.write '404 Not Found'
5
- response.finish
6
- end
1
+ app_class = Class.new(Rack::App)
2
+ not_found_properties = {
3
+ :user_defined_logic => lambda {
4
+ response.status= 404
5
+ response.write '404 Not Found'
6
+ response.finish
7
+ },
8
+ :request_method => 'GET',
9
+ :request_path => '\404',
10
+ :description => 'page not found',
11
+ :serializer => lambda { |o| String(o) },
12
+ :app_class => app_class
13
+ }
14
+
15
+ Rack::App::Endpoint::NOT_FOUND = Rack::App::Endpoint.new(not_found_properties)
@@ -21,7 +21,7 @@ module Rack::App::Test
21
21
  end
22
22
  end
23
23
 
24
- [:get, :post, :put, :delete, :options].each do |request_method|
24
+ [:get, :post, :put, :delete, :options, :patch].each do |request_method|
25
25
  define_method(request_method) do |properties|
26
26
  properties ||= Hash.new
27
27
  url = properties.delete(:url)
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
7
7
 
8
8
  spec.name = "rack-app"
9
9
  spec.version = File.read(File.join(File.dirname(__FILE__), 'VERSION')).strip
10
- spec.authors = ["Adam Luzsi"]
11
- spec.email = ["adamluzsi@gmail.com"]
10
+ spec.authors = ["Adam Luzsi","Daniel Nagy"]
11
+ spec.email = ["adamluzsi@gmail.com","naitodai@gmail.com"]
12
12
 
13
13
  spec.summary = %q{Your next favourite, performance designed micro framework!}
14
14
  spec.description = %q{Your next favourite rack based micro framework that is totally addition free! Have a cup of awesomeness with your to performance designed framework!}
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
+ - Daniel Nagy
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
12
+ date: 2016-01-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -70,6 +71,7 @@ description: Your next favourite rack based micro framework that is totally addi
70
71
  free! Have a cup of awesomeness with your to performance designed framework!
71
72
  email:
72
73
  - adamluzsi@gmail.com
74
+ - naitodai@gmail.com
73
75
  executables: []
74
76
  extensions: []
75
77
  extra_rdoc_files: []