sinatra_simple_router 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDM1N2Q0YmVlZjI5NWVhODcwMDdiODA5OWE1YjI0MDliYTFkZjA1Yw==
4
+ MzNjMTU0NDRhYTNmYTE5NTRiZjkxZTdhMjVkZGEyNzk4YjMzMjM4OQ==
5
5
  data.tar.gz: !binary |-
6
- Njg3NWJjOWRkNjExZjRjOTFlNTZlODhmNDgzZmJhNGJiNGVkNWRkMw==
6
+ ZWNhY2Q3NjQ2MmJkNGZlYWRiZDg5ZGVjN2NhYTY3M2Q4OWU3ZGVkYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NmQyZmZiYzQyMTc4N2E5NjkwZmJiZDBmMmY3YjFmMDVjNGY0Nzg0Y2E0NDYw
10
- MTYyNTEyNWVlZGU0ZTVlZDI1MDI1MjQ4OTAxZTE0ZjJhODlkNzJkMWM5MmNj
11
- ODJhNDNlODFjMzJhNTc4Y2FmMmI3YjYxODRlMjVjOGRjNzAyODY=
9
+ NWFkNjU4YTljZDM5NmJlYmIwNTgxNWE1MTAwNTc3ZDY2OTk3YzgyMjhkMWIz
10
+ NzIwYTAyNTRmNzVmZjQzNDJiODg1NDlmYTA3ZmMxMzc3MDc4MDUyN2MwNjVi
11
+ YzljMjlkMmYzZWUyNzJkM2Q3YmQzOGYyNTA1NDRlZjc3MjhjNjg=
12
12
  data.tar.gz: !binary |-
13
- NDQ1YzNkYWI5MWVmY2MxNTE5YzUyOGE0YTdhNDY5ZmY0ZTE5YjE5M2I5ZTNm
14
- ODZiZWEwMzZlOGRhOGY2Y2JhMmNhYWFiYzhmYzBlMDI2MjQ0NDc3NzVmOGMy
15
- NGJmOTk0NDg5MTAxNzM4YWUwODg2M2JjODkzYTM5ZjEyODQyMDA=
13
+ NTk3YzM0N2MzN2Y1ZDAzNzZhNzJiNGJmYjVjNjBkZGJlZjhmOTk0YjAxZTQ4
14
+ NzNjMWNmZGQ4ZmU2MmMxODk3YjJkNjE2MWExZjU1ZWRhMGQ3ZGYxNDA1YjVi
15
+ NDNkNDU1NzFiMDE2ZTY5NWZhMWYxNTk2MGNmOWM1NzI2ZGYwZmU=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SinatraSimpleRouter
2
2
 
3
- Simple routing abstraction to Sinatra applications.
3
+ Simple routing abstraction for Sinatra applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -35,20 +35,22 @@ class UsersController < SinatraSimpleRouter::Controller
35
35
  end
36
36
  end
37
37
 
38
+ class ItemsController < SinatraSimpleRouter::Controller
39
+ def show
40
+ @item = Item.find(params[:id])
41
+ render json: @item
42
+ end
43
+ end
44
+
38
45
  class Application < Sinatra::Base
39
46
  include SinatraSimpleRouter
40
-
47
+
41
48
  match :get, "/users/:id", UsersController, :show
42
49
  match :patch, "/users/:id", UsersController, :update
50
+ match :get, "/items/:id.json", ItemsController, :show
43
51
  end
44
52
  ```
45
53
 
46
- ## Missing features
47
-
48
- - Support before/after filters
49
- - Named routes + Helpers
50
- - Support more than one method (such as: match [:patch, :put] ...)
51
-
52
54
  ## Contributing
53
55
 
54
56
  1. Fork it
@@ -4,6 +4,22 @@ module SinatraSimpleRouter
4
4
  @app = app
5
5
  end
6
6
 
7
+ def render(options = {})
8
+ if code=options[:status].to_i and code > 0
9
+ status code
10
+ end
11
+
12
+ if html=options[:html]
13
+ content_type "text/html"
14
+ body html.to_s
15
+ elsif json=options[:json]
16
+ content_type "application/json"
17
+ body json.to_json
18
+ else
19
+ raise ArgumentError.new("Unknown format in #{options.keys.sort}")
20
+ end
21
+ end
22
+
7
23
  def method_missing(method, *args, &block)
8
24
  if @app.respond_to?(method)
9
25
  (self.instance_variables - [:"@app"]).each do |v|
@@ -1,3 +1,3 @@
1
1
  module SinatraSimpleRouter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,10 +3,37 @@ require "sinatra_simple_router"
3
3
 
4
4
  module SinatraSimpleRouter
5
5
  describe Controller do
6
- describe "method delegation" do
7
- let(:app) { double("App", body: "") }
8
- let(:controller) { ItemsController.new(app) }
6
+ let(:app) { double("App", body: "") }
7
+ let(:controller) { ItemsController.new(app) }
8
+
9
+ describe "#render" do
10
+ let(:content) { double("Content") }
11
+ let(:json) { double("JSON") }
12
+
13
+ it "renders json" do
14
+ expect(app).to receive(:content_type).with("application/json")
15
+ expect(app).to receive(:body).with(json)
16
+ expect(content).to receive(:to_json).and_return(json)
17
+
18
+ controller.render json: content
19
+ end
20
+
21
+ it "renders html" do
22
+ expect(app).to receive(:content_type).with("text/html")
23
+ expect(app).to receive(:body).with(content)
24
+ expect(content).to receive(:to_s).and_return(content)
9
25
 
26
+ controller.render html: content
27
+ end
28
+
29
+ it "sets the status" do
30
+ app.stub(:content_type)
31
+ expect(app).to receive(:status).with(201)
32
+ controller.render html: "", status: 201
33
+ end
34
+ end
35
+
36
+ describe "method delegation" do
10
37
  context "when the method is present in the Sinatra class" do
11
38
  it "delegates to the class" do
12
39
  expect(app).to receive(:body)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_simple_router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - elvio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-25 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler