coast 0.9.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Coast
2
- VERSION = "0.9.9"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "rubygems"
2
- require "bundler"
3
- Bundler.require(:default, :test)
2
+ require "micro_test"
3
+ require "micro_mock"
4
4
  require "active_support/all"
5
5
  require File.join(File.dirname(__FILE__), "..", "lib", "coast")
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 1.0.0
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-28 00:00:00.000000000 Z
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -27,38 +27,54 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: micro_test
32
48
  requirement: !ruby/object:Gem::Requirement
33
49
  none: false
34
50
  requirements:
35
- - - ~>
51
+ - - ! '>='
36
52
  - !ruby/object:Gem::Version
37
- version: '0.3'
53
+ version: '0'
38
54
  type: :development
39
55
  prerelease: false
40
56
  version_requirements: !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
- - - ~>
59
+ - - ! '>='
44
60
  - !ruby/object:Gem::Version
45
- version: '0.3'
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: micro_mock
48
64
  requirement: !ruby/object:Gem::Requirement
49
65
  none: false
50
66
  requirements:
51
- - - ~>
67
+ - - ! '>='
52
68
  - !ruby/object:Gem::Version
53
- version: '1.0'
69
+ version: '0'
54
70
  type: :development
55
71
  prerelease: false
56
72
  version_requirements: !ruby/object:Gem::Requirement
57
73
  none: false
58
74
  requirements:
59
- - - ~>
75
+ - - ! '>='
60
76
  - !ruby/object:Gem::Version
61
- version: '1.0'
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: pry
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -107,19 +123,15 @@ dependencies:
107
123
  - - ! '>='
108
124
  - !ruby/object:Gem::Version
109
125
  version: '0'
110
- description: Resourceful behavior for Rails controllers with a simple DSL.
126
+ description: A small mixin for Rails controllers that provides restful behavior.
111
127
  email:
112
128
  - natehop@gmail.com
113
129
  executables: []
114
130
  extensions: []
115
131
  extra_rdoc_files: []
116
132
  files:
117
- - lib/coast.rb
118
133
  - lib/coast/version.rb
119
- - Gemfile
120
- - Gemfile.lock
121
- - README.md
122
- - LICENSE.txt
134
+ - lib/coast.rb
123
135
  - test/test_coast.rb
124
136
  homepage: https://github.com/hopsoft/coast
125
137
  licenses:
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activesupport"
4
-
5
- group :test do
6
- gem "micro_test"
7
- gem "micro_mock"
8
- gem "pry"
9
- gem "pry-stack_explorer"
10
- # gem "awesome_print"
11
- end
@@ -1,32 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- activesupport (3.2.11)
5
- i18n (~> 0.6)
6
- multi_json (~> 1.0)
7
- binding_of_caller (0.6.8)
8
- coderay (1.0.8)
9
- i18n (0.6.1)
10
- method_source (0.8.1)
11
- micro_mock (1.0.0)
12
- micro_test (0.3.5)
13
- os
14
- multi_json (1.5.0)
15
- os (0.9.6)
16
- pry (0.9.11.4)
17
- coderay (~> 1.0.5)
18
- method_source (~> 0.8)
19
- slop (~> 3.4)
20
- pry-stack_explorer (0.4.7)
21
- binding_of_caller (~> 0.6.8)
22
- slop (3.4.3)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- activesupport
29
- micro_mock
30
- micro_test
31
- pry
32
- pry-stack_explorer
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 Nathan Hopkins
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,189 +0,0 @@
1
- # Coast
2
-
3
- ## Providing resourceful behavior for [Rails controllers](http://guides.rubyonrails.org/action_controller_overview.html)
4
-
5
- ![Coast GEM](http://hopsoft.github.com/coast/images/coast.png)
6
-
7
- ### ...if only the REST of life were this easy
8
-
9
- Simply include the Coast module in your controller and get these actions for free.
10
-
11
- `new` `edit` `index` `show` `create` `update` `destroy`
12
-
13
- But wait... there's more.
14
-
15
- * **Lightweight** - about 200 lines of code... *you can grok it in 5 minutes by skimming lib/coast.rb*
16
- * **Unobtrusive** - no monkey patches
17
- * **Flexible** - support for html, xml, and json formats
18
- * **Familiar** - simple DSL for hooking into action callbacks
19
- * **Secure** - implicit authorization with your favorite libs... *such as [CanCan](https://github.com/ryanb/cancan)*
20
-
21
- ### Works best when you stick to [Rails conventions](http://guides.rubyonrails.org/getting_started.html)
22
-
23
- ## Quick-start for the lazy
24
-
25
- Assume you have a simple app structure for beach bums.
26
-
27
- ```bash
28
- app/controllers/beach_bums_controller.rb
29
- app/models/beach_bum.rb
30
- ```
31
-
32
- Install the GEM.
33
-
34
- ```bash
35
- $gem install coast
36
- ```
37
-
38
- Tweak some files.
39
-
40
- ```ruby
41
- # config/routes.rb
42
- Beach::Application.routes.draw do
43
- resources :beach_bums
44
- end
45
- ```
46
-
47
- ```ruby
48
- # app/controllers/beach_bums_controller.rb
49
- class BeachBumsController < ApplicationController
50
- include Coast
51
- end
52
- ```
53
-
54
- Congratulations... you now have a RESTful API for **beach bums**.
55
-
56
- ## Callbacks
57
-
58
- Coast uses a [Sinatra](http://www.sinatrarb.com/) like DSL to provide hooks into the action lifecycle.
59
-
60
- The following hooks are supported for each action.
61
-
62
- * `before` *- before any other action logic is performed... just like a [Rails before_filter](http://guides.rubyonrails.org/action_controller_overview.html#filters)*
63
- * `respond_to` *- after authorization and db work but before rendering or redirecting*
64
- * `after` *- after all other action logic is performed... just like a [Rails after_filter](http://guides.rubyonrails.org/action_controller_overview.html#filters)*
65
-
66
- ### How to use the callbacks
67
-
68
- ```ruby
69
- # app/controllers/beach_bums_controller.rb
70
- class BeachBumsController < ApplicationController
71
- include Coast
72
-
73
- before :show do
74
- # take control and load a 'beach_bum' instead of letting Coast do it for us
75
- @resourceful_item = BeachBum.find(params[:id])
76
-
77
- # Coast will implicitly create an @beach_bum variable that references @resourceful_item
78
- # cool eh?
79
- end
80
-
81
- respond_to :show do
82
- # take control of rendering or redirecting instead of letting Coast do it for us
83
- render :text => "Out surfing."
84
- end
85
-
86
- after :show do
87
- # do some last minute housekeeping after every thing else is done
88
- Rails.logger.info "Hey brah... we just completed the show action."
89
- end
90
-
91
- end
92
- ```
93
-
94
- ## Authorization
95
-
96
- Coast implicitly calls an authorize method prior to executing any action logic.
97
-
98
- You have complete control over this method. Here's an example.
99
-
100
- ```ruby
101
- # app/controllers/beach_bums_controller.rb
102
- class BeachBumsController < ApplicationController
103
- include Coast
104
- set_authorize_method :authorize
105
-
106
- def authorize(action, data, request)
107
- # restrict all RESTful actions
108
- raise "Unauthorized"
109
- end
110
-
111
- rescue_from Exception do |ex|
112
- render :text => "Not Allowed", :status => 401
113
- end
114
- end
115
- ```
116
-
117
- Note the authorize method signature. The first arg is the **action** being performed. The second arg is the **record(s)** being operated on. The last arg is the **request** object.
118
-
119
- While originally written to support [CanCan](https://github.com/ryanb/cancan), its pretty simple to take control and manage authorization yourself.
120
-
121
- ## Localization
122
-
123
- Enable I18n internationalization with a simple method call.
124
-
125
- ```ruby
126
- # app/controllers/beach_bums_controller.rb
127
- class BeachBumsController < ApplicationController
128
- include Coast
129
- set_localized true
130
- end
131
- ```
132
-
133
- ## Advanced Usage
134
-
135
- Coast comes with few tricks up its sleeve.
136
-
137
- If your model and controller names deviate from Rails conventions, you can explicitly set the model like so.
138
-
139
- ```ruby
140
- # app/controllers/beach_bums_controller.rb
141
- class BeachBumsController < ApplicationController
142
- include Coast
143
- set_resourceful_model SurferDude
144
- end
145
- ```
146
-
147
- You can conditionally prevent mutating behavior on the server by setting an instance variable like so. *It's a little arcane, but that's on purpose.*
148
-
149
- ```ruby
150
- # app/controllers/beach_bums_controller.rb
151
- class BeachBumsController < ApplicationController
152
- include Coast
153
-
154
- before :create do
155
- # prevent the user from actually creating a record
156
- @skip_db_create = true
157
- end
158
-
159
- before :update do
160
- # prevent the user from actually saving a record
161
- @skip_db_update = true
162
- end
163
-
164
- before :destroy do
165
- # prevent the user from actually destroying a record
166
- @skip_db_destroy = true
167
- end
168
-
169
- end
170
- ```
171
-
172
- ## Running the Tests
173
-
174
- ```bash
175
- $ gem install coast
176
- $ gem unpack coast
177
- $ cd coast-[VERSION]
178
- $ bundle
179
- $ bundle exec mt
180
- ```
181
-
182
- Ahh... passing tests.
183
-
184
- ## Nods
185
-
186
- [I'm tired of writing RESTful boilerplate (& scaffold is overkill), so I'm stoked natehop released the Coast gem.](https://twitter.com/tehviking/status/189739333857710080)
187
-
188
- -- Brandon Hayes, April 10, 2012
189
-