restaurant 0.0.3 → 0.0.4

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: 5d5122a098f9caa7cc338db255ba09004f7ccf66
4
- data.tar.gz: c3d345db89308e5c3290712e9107a0ce5e72fd4c
3
+ metadata.gz: 34693c2b7b5744a24cb8d8b5996a0e71f864c224
4
+ data.tar.gz: 05751994c3c8c46fa048b739ef440f0b61a1b6df
5
5
  SHA512:
6
- metadata.gz: faeea0c7030f4a52afde512659ed888b5535ed1abe9ca06c913b8b643ffe39074cb857ec0035e9bf9f8b77e0d94c2d5d5c45da7ae01ed9304c6a0f03b217a95a
7
- data.tar.gz: 7b66d037c43da749f4829d55a80ef64282544580fe07902b9ee4cbbe99d7fca79d144632055453dceae2b26f5376a7e242f00ac940cc7708875e8d4cf9154ae1
6
+ metadata.gz: ed5df57787d9ae463a3b9f0163470c613769efc904add512f243d06db0a4b2ff421236d7909976accd30a02ede8a90a3fba64389a1e2e79f13e90093fd7bd91f
7
+ data.tar.gz: f19f4861e947ea6b6b1cb94907ee48f22c8a7654c21d35def38d68137b97629bacaa377b7d1b0302918e49f5466c8c5d6c205289708838ef7674e2a56d4f3083
@@ -1,4 +1,12 @@
1
1
  module Restaurant::RestfulActions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ rescue_from ActiveRecord::RecordNotFound do
6
+ head 404
7
+ end
8
+ end
9
+
2
10
  def index
3
11
  respond_with model.scoped, :only => current_role.allowed_attributes
4
12
  end
@@ -22,14 +30,24 @@ module Restaurant::RestfulActions
22
30
  private
23
31
 
24
32
  def model
25
- self.class.name.sub(/Controller$/, "").singularize.constantize
33
+ model_name.constantize
34
+ rescue NameError
35
+ define_model
36
+ end
37
+
38
+ def model_name
39
+ @model_name ||= self.class.name.sub(/Controller$/, "").singularize
26
40
  end
27
41
 
28
42
  def model_param
29
- params[model.name.underscore]
43
+ params[model_name.underscore]
30
44
  end
31
45
 
32
46
  def resource
33
47
  model.find(params[:id])
34
48
  end
49
+
50
+ def define_model
51
+ Object.const_set(model_name, Class.new(ActiveRecord::Base))
52
+ end
35
53
  end
@@ -1,3 +1,3 @@
1
1
  module Restaurant
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura