rack-autocrud 0.1.19 → 0.1.20

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 +9 -7
  2. data/lib/rack/autocrud.rb +7 -0
  3. metadata +2 -2
data/README.md CHANGED
@@ -87,15 +87,17 @@ The routing is simple. You have a model *Models::Person*. You've added something
87
87
  _config.ru_. This middleware will dynamically create a _Sinatra::Base_ subclass called *Endpoints::Person*
88
88
  (if it already exists, these routes are added to it) which will contain the following routes:
89
89
 
90
- | Route | Action | HTTP Response Code |
91
- | ----------- | -------------------------------| ------------------ |
92
- | get / | List all _Person_ entries | 200 / 403 |
93
- | post / | Create a new _Person_ | 201 / 402 |
94
- | get /:id | Retrieve a _Person_ | 200 |
95
- | put /:id | Update a _Person_ | 201 / 402 |
96
- | delete /:id | Destroy a _Person_ | 204 |
90
+ | Route | Action | HTTP Response Code |
91
+ | ----------- | --------------------------------| ------------------ |
92
+ | get / | List all _Person_ entries | 200 / 403 |
93
+ | post / | Create a new _Person_ | 201 / 402 |
94
+ | get /:id | Retrieve a _Person_ | 200 |
95
+ | put /:id | Update a _Person_ | 201 / 402 |
96
+ | delete /:id | Destroy a _Person_ | 204 |
97
+ | get /count | Get a count of _Person_ entries | 200 / 403 |
97
98
 
98
99
  The middleware will route based on the URI. Thus, _/person_ would correspond to *Endpoints::Person*'s _get /_ route.
100
+ The _/count_ route returns the total number of _Person_ entries in the database, if _COLLECTABLE_ is set.
99
101
 
100
102
  Overriding Generated Routes
101
103
  ===========================
data/lib/rack/autocrud.rb CHANGED
@@ -92,6 +92,13 @@ module Rack
92
92
  return nil
93
93
  end
94
94
 
95
+ get '/count' do
96
+ halt [ 403, '{ "error": "Access Denied" }' ] unless model_klass.const_defined?(:COLLECTABLE) && model.const_get(:COLLECTABLE)
97
+
98
+ # Return the count
99
+ { :count => model.all.count }.to_json
100
+ end
101
+
95
102
  get '/' do
96
103
  halt [ 403, '{ "error": "Access Denied" }' ] unless model_klass.const_defined?(:COLLECTABLE) && model.const_get(:COLLECTABLE)
97
104
 
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.19
4
+ version: 0.1.20
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: 2013-01-26 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json