restaurant 0.1.0 → 0.1.1

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: 49cc226f4daf8e7f58cd29786cbc7791ede0710a
4
- data.tar.gz: e674d4933f37fab45fe0ed45f8d63910a04b8077
3
+ metadata.gz: 9cc774878cfd70d875198554dc08a0c02699de0c
4
+ data.tar.gz: a9f90a959400a81935d5441a21ddc3770264368a
5
5
  SHA512:
6
- metadata.gz: 2df6791bafce8d9db067d18e6e8d71dfab0c4133ca5e4cb512e3137b0caa4c54d17a835a197656797f06bd863f2aa7a157304784c77c673cea60595b5c7bca84
7
- data.tar.gz: c5e1e05f9dc39dde654c58aed854d4cff560fd0be8582d47d0f2735178e7cda6e958b447de550050a69645394aed9953f2fc6bdccfdfc1d3770112aa694dae18
6
+ metadata.gz: 5b11d73e5068aad446ab0ed0b23191236c0729ea848bdf344ff35c9153d1bb463e6e426a7abc9184d94e9e5cd22600fca8adec9300c7a1de91becf809aa0a765
7
+ data.tar.gz: ce710ac1bff61b2d2cb876aaa8ee37d69b0c2de32ee7ba41737d3cc276d6ea8101df18bb14a4ce7e3bbe600bbcf8010e66041a2eeb1d3f0b8f61e58855317603
data/README.md CHANGED
@@ -1,55 +1,43 @@
1
1
  # Restaurant
2
- Restaurant serves your data via auto-defined RESTful API on your rails application.
3
- All you have to do is to edit config/routes.rb.
2
+ Restaurant serves your data via auto-defined RESTful API on your rails application.
4
3
 
5
- ## Get started
4
+ ## Usage
6
5
  ```
7
- $ rails new example
8
- $ cd example
9
-
10
- $ vi Gemfile
11
- source "https://rubygems.org"
12
- gem "rails", "~> 3.2.13"
13
- gem "restaurant"
14
- gem "sqlite3"
15
-
16
- $ vi config/routes.rb
17
- Example::Application.routes.draw do
18
- namespace :v1 do
19
- Restaurant::Router.route(self)
20
- end
21
- end
22
-
23
6
  $ brew install mongodb
24
7
  $ mongod --fork
25
8
 
9
+ $ rails new example
10
+ $ cd example
11
+
12
+ $ echo 'gem "restaurant"' >> Gemfile
26
13
  $ bundle install
14
+
27
15
  $ rails g mongoid:config
28
16
  $ rails c
29
17
 
30
18
  [1] pry(main)> app.accept = "application/json"
31
19
  => "application/json"
32
- [2] pry(main)> app.post "/v1/recipes.json", recipe: { title: "created" }
20
+ [2] pry(main)> app.post "/recipes", recipe: { title: "created" }
33
21
  => 201
34
22
  [3] pry(main)> JSON.parse(app.response.body)
35
23
  => {"title"=>"created", "_id"=>"51963fe9f02da4c1f8000001"}
36
- [4] pry(main)> app.get "/v1/recipes/51963fe9f02da4c1f8000001.json"
24
+ [4] pry(main)> app.get "/recipes/51963fe9f02da4c1f8000001"
37
25
  => 200
38
26
  [5] pry(main)> JSON.parse(app.response.body)
39
27
  => {"title"=>"created", "_id"=>"51963fe9f02da4c1f8000001"}
40
- [6] pry(main)> app.put "/v1/recipes/51963fe9f02da4c1f8000001.json", recipe: { title: "updated" }
28
+ [6] pry(main)> app.put "/recipes/51963fe9f02da4c1f8000001", recipe: { title: "updated" }
41
29
  => 204
42
- [7] pry(main)> app.get "/v1/recipes/51963fe9f02da4c1f8000001.json"
30
+ [7] pry(main)> app.get "/recipes/51963fe9f02da4c1f8000001"
43
31
  => 200
44
32
  [8] pry(main)> JSON.parse(app.response.body)
45
33
  => {"title"=>"updated", "_id"=>"51963fe9f02da4c1f8000001"}
46
- [9] pry(main)> app.get "/v1/recipes.json"
34
+ [9] pry(main)> app.get "/recipes"
47
35
  => 200
48
36
  [10] pry(main)> JSON.parse(app.response.body)
49
37
  => [{"title"=>"updated", "_id"=>"51963fe9f02da4c1f8000001"}]
50
- [11] pry(main)> app.delete "/v1/recipes/51963fe9f02da4c1f8000001.json"
38
+ [11] pry(main)> app.delete "/recipes/51963fe9f02da4c1f8000001"
51
39
  => 204
52
- [12] pry(main)> app.get "/v1/recipes.json"
40
+ [12] pry(main)> app.get "/recipes"
53
41
  => 200
54
42
  [13] pry(main)> JSON.parse(app.response.body)
55
43
  => []
data/lib/restaurant.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "mongoid"
2
2
  require "restaurant/actions"
3
+ require "restaurant/railtie"
3
4
  require "restaurant/router"
@@ -0,0 +1,12 @@
1
+ module Restaurant
2
+ class Railtie < Rails::Railtie
3
+ config.after_initialize do
4
+ Rails.application.reload_routes!
5
+ unless Restaurant::Router.called?
6
+ Rails.application.routes.append do
7
+ Restaurant::Router.route(self)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -29,8 +29,15 @@
29
29
  #
30
30
  module Restaurant
31
31
  class Router
32
- def self.route(*args)
33
- new(*args).route
32
+ class << self
33
+ def route(*args)
34
+ new(*args).route
35
+ @called = true
36
+ end
37
+
38
+ def called?
39
+ !!@called
40
+ end
34
41
  end
35
42
 
36
43
  attr_reader :router
@@ -1,3 +1,3 @@
1
1
  module Restaurant
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restaurant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - lib/restaurant/actions.rb
120
+ - lib/restaurant/railtie.rb
120
121
  - lib/restaurant/router.rb
121
122
  - lib/restaurant/version.rb
122
123
  - lib/restaurant.rb