rack-autocrud 0.1.14 → 0.1.15

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.
Files changed (3) hide show
  1. data/README.md +27 -12
  2. data/lib/rack/autocrud.rb +5 -1
  3. metadata +2 -2
data/README.md CHANGED
@@ -53,6 +53,33 @@ This would assume you only want CRUD-based routing. You can also _use_ this midd
53
53
  use Rack::AutoCRUD, :model_namespace => 'Models', :endpoint_namespace => 'Endpoints'
54
54
  ```
55
55
 
56
+ Auto-Inclusion of Other Modules
57
+ ===============================
58
+
59
+ This middleware also takes an option _:includes_ which can be used to automatically
60
+ include other modules (e.g. helpers) when creating and/or patching endpoints.
61
+
62
+ For example:
63
+
64
+ ```ruby
65
+ use Rack::AutoCRUD, :model_namespace => 'Models', :endpoint_namespace => 'Endpoints', :includes => [ Your::HelperModule ]
66
+ ```
67
+
68
+ Setting Sinatra Options
69
+ =======================
70
+
71
+ You can set Sinatra options for your auto-generated endpoints by passing the ``:sinatra_opts``
72
+ option to this middleware.
73
+
74
+ For example:
75
+
76
+ ```ruby
77
+ use Rack::AutoCRUD, :model_namespace => 'Models', :endpoint_namespace => 'Endpoints', :sinatra_opts => { :sessions => false }
78
+ ```
79
+
80
+ Which can be extremely useful if you're handling sessions at a higher level than the
81
+ auto-generated endpoints.
82
+
56
83
  How Routing Works
57
84
  =================
58
85
 
@@ -175,15 +202,3 @@ def set_request_body(new_body,content_type='text/json')
175
202
 
176
203
  where *new_body* is expected to be a string.
177
204
 
178
- Auto-Inclusion of Other Modules
179
- ===============================
180
-
181
- This middleware also takes an option _:includes_ which can be used to automatically
182
- include other modules (e.g. helpers) when creating and/or patching endpoints.
183
-
184
- For example:
185
-
186
- ```ruby
187
- use Rack::AutoCRUD, :model_namespace => 'Models', :endpoint_namespace => 'Endpoints', :includes => [ Your::HelperModule ]
188
- ```
189
-
data/lib/rack/autocrud.rb CHANGED
@@ -20,7 +20,8 @@ module Rack
20
20
  @app = app
21
21
  @model_namespace = options[:model_namespace]
22
22
  @endpoint_namespace = options[:endpoint_namespace]
23
- @includes = options[:includes]
23
+ @includes = options[:includes] || []
24
+ @sinatra_opts = options[:sinatra_opts] || {}
24
25
  @endpoint_mod = nil
25
26
  @model_mod = nil
26
27
  end
@@ -74,6 +75,9 @@ module Rack
74
75
  # Add in any specified helpers
75
76
  @includes.each { |inc| endpoint_klass.send(:include,inc) } unless @includes.nil?
76
77
 
78
+ # Set any Sinatra options
79
+ @sinatra_opts.each { |sopt,val| endpoint_klass.send(:set,sopt,val) }
80
+
77
81
  # Patch in the routes
78
82
  endpoint_klass.class_exec(model_klass,endpoint,env) { |model,endpoint,env|
79
83
  def set_request_body(new_body,content_type='text/json')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-autocrud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json