toast 0.1.1 → 0.2.0

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.
@@ -1,6 +1,8 @@
1
1
  module Toast
2
2
  class AssociateCollection < Resource
3
3
 
4
+ attr_reader :model
5
+
4
6
  def initialize model, id, subresource_name
5
7
  unless model.toast_config.exposed_associations.include? subresource_name
6
8
  raise ResourceNotFound
@@ -1,6 +1,8 @@
1
1
  module Toast
2
2
  class Attribute < Resource
3
3
 
4
+ attr_reader :model
5
+
4
6
  def initialize model, id, attribute_name
5
7
  unless model.toast_config.exposed_attributes.include? attribute_name
6
8
  raise ResourceNotFound
@@ -12,6 +12,7 @@ module Toast
12
12
  @media_type = "application/json"
13
13
  @exposed_attributes = []
14
14
  @exposed_associations = []
15
+ @disallow_methods = []
15
16
  @in_collection = ConfigDSL::InCollection.new model, self
16
17
  end
17
18
 
@@ -24,7 +25,6 @@ module Toast
24
25
  @exposed_associations << attr_or_assoc
25
26
  end
26
27
  end
27
-
28
28
  end
29
29
 
30
30
  def fields *arg
@@ -32,6 +32,15 @@ module Toast
32
32
  self.fields = *arg
33
33
  end
34
34
 
35
+ def disallow_methods= *arg
36
+ @disallow_methods.push *ConfigDSL.sanitize(arg,"disallow methods")
37
+ end
38
+
39
+ def disallow_methods *arg
40
+ return(@disallow_methods) if arg.empty?
41
+ self.disallow_methods = *arg
42
+ end
43
+
35
44
  attr_reader :exposed_attributes, :exposed_associations
36
45
 
37
46
  def collections= collections=[]
data/lib/toast/record.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Toast
2
2
  class Record < Resource
3
+
4
+ attr_reader :model
3
5
 
4
6
  def initialize model, id
5
7
  @model = model
@@ -27,7 +29,7 @@ module Toast
27
29
  end
28
30
 
29
31
  @record.update_attributes payload
30
- {
32
+ {
31
33
  :json => @record.exposed_attributes,
32
34
  :status => :ok,
33
35
  :location => @record.uri
@@ -44,6 +46,7 @@ module Toast
44
46
  def delete
45
47
  @record.destroy
46
48
  {
49
+ :nothing => true,
47
50
  :status => :ok
48
51
  }
49
52
  end
@@ -72,6 +72,9 @@ module Toast
72
72
  end
73
73
 
74
74
  def apply method, payload
75
+
76
+ raise MethodNotAllowed if self.model.toast_config.disallow_methods.include?(method.downcase)
77
+
75
78
  case method
76
79
  when "PUT","POST"
77
80
  self.send(method.downcase, ActiveSupport::JSON.decode(payload))
@@ -1,6 +1,8 @@
1
1
  module Toast
2
2
  class RootCollection < Resource
3
3
 
4
+ attr_reader :model
5
+
4
6
  def initialize model, subresource_name
5
7
 
6
8
  subresource_name ||= "all"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toast
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Annies