sinatra_resource 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -33,7 +33,7 @@ module SinatraResource
33
33
  def document_for_post(role, model, resource_config, leaf, parent_document, child_assoc)
34
34
  check_permission(:create, role, resource_config)
35
35
  check_params(:create, role, resource_config, leaf)
36
- do_callback(:before_create, resource_config, nil)
36
+ do_callback(:before_create, resource_config, nil, parent_document)
37
37
  document = if resource_config[:parent]
38
38
  create_nested_document!(parent_document, child_assoc, model)
39
39
  else
@@ -42,7 +42,7 @@ module SinatraResource
42
42
  if resource_config[:parent]
43
43
  make_related(parent_document, document, resource_config)
44
44
  end
45
- do_callback(:after_create, resource_config, document)
45
+ do_callback(:after_create, resource_config, document, parent_document)
46
46
  document
47
47
  end
48
48
 
@@ -57,13 +57,13 @@ module SinatraResource
57
57
  else
58
58
  find_document!(model, id)
59
59
  end
60
- do_callback(:before_update, resource_config, document)
60
+ do_callback(:before_update, resource_config, document, parent_document)
61
61
  document = if resource_config[:parent]
62
62
  update_nested_document!(parent_document, child_assoc, model, id)
63
63
  else
64
64
  update_document!(model, id)
65
65
  end
66
- do_callback(:after_update, resource_config, document)
66
+ do_callback(:after_update, resource_config, document, parent_document)
67
67
  document
68
68
  end
69
69
 
@@ -78,13 +78,13 @@ module SinatraResource
78
78
  else
79
79
  find_document!(model, id)
80
80
  end
81
- do_callback(:before_destroy, resource_config, document)
81
+ do_callback(:before_destroy, resource_config, document, parent_document)
82
82
  document = if resource_config[:parent]
83
83
  delete_nested_document!(parent_document, child_assoc, model, id)
84
84
  else
85
85
  delete_document!(model, id)
86
86
  end
87
- do_callback(:after_destroy, resource_config, document)
87
+ do_callback(:after_destroy, resource_config, document, parent_document)
88
88
  document
89
89
  end
90
90
 
@@ -122,11 +122,30 @@ module SinatraResource
122
122
  convert(object)
123
123
  end
124
124
 
125
- def do_callback(name, resource_config, document)
125
+ # Execute a callback.
126
+ #
127
+ # @param [Symbol] name
128
+ # Valid values include:
129
+ # * :before_create, :before_update, :before_destroy
130
+ # * :after_create, :after_update, :after_destroy
131
+ #
132
+ # @param [Hash] resource_config
133
+ #
134
+ # @param [MongoMapper::Document, nil] document
135
+ #
136
+ # @param [MongoMapper::Document, nil] parent_document
137
+ #
138
+ # @return [undefined]
139
+ def do_callback(name, resource_config, document, parent_document)
126
140
  proc = resource_config[:callbacks][name]
127
141
  return unless proc
128
- if document
142
+
143
+ if document && parent_document
144
+ proc.call(self, document, parent_document)
145
+ elsif document
129
146
  proc.call(self, document)
147
+ elsif parent_document
148
+ proc.call(self, parent_document)
130
149
  else
131
150
  proc.call(self)
132
151
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_resource}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David James"]
12
- s.date = %q{2009-10-29}
12
+ s.date = %q{2009-10-30}
13
13
  s.description = %q{A DSL for creating RESTful actions with Sinatra and MongoMapper. It embraces the Resource Oriented Architecture as explained by Leonard Richardson and Sam Ruby.}
14
14
  s.email = %q{djames@sunlightfoundation.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David James
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-29 00:00:00 -04:00
12
+ date: 2009-10-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency