bounce 0.0.1

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.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 by John Thomas Marino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ bounce
2
+ ======
3
+
4
+ `bounce` will save and return an active record object. This results in a nice refactor of update and create actions in your controllers. This works really well with `respond_with`.
5
+
6
+ Refactor this:
7
+
8
+ def create
9
+ article = Article.new(params[:article])
10
+ if article.save
11
+ redirect_to article
12
+ else
13
+ render :new
14
+ end
15
+ end
16
+
17
+ def update
18
+ article = Article.find(params[:id])
19
+ if article.update_attributes(params[:article])
20
+ redirect_to article
21
+ else
22
+ render :edit
23
+ end
24
+ end
25
+
26
+ Into this:
27
+
28
+ respond_to :html
29
+
30
+ def create
31
+ article = Article.new(params[:article])
32
+ respond_with article.bounce
33
+ end
34
+
35
+ def update
36
+ article = Article.find(params[:id])
37
+ respond_with article.bounce(params[:article])
38
+ end
39
+
40
+ If you use Voxdolo's [decent_exposure](https://github.com/voxdolo/decent_exposure) you can do this:
41
+
42
+ respond_to :html
43
+ expose(:article)
44
+
45
+ def create
46
+ respond_with article.bounce
47
+ end
48
+ alias update create
49
+
50
+ If you have more than one controller, I'll bet you do, extract the `respond_to :html` into the application controller. Now this:
51
+
52
+ expose(:article)
53
+
54
+ def create
55
+ respond_with article.bounce
56
+ end
57
+ alias update create
58
+
59
+ Install
60
+ -------
61
+
62
+ Add to your Gemfile in Rails:
63
+
64
+ gem 'bounce'
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,13 @@
1
+ module Bounce
2
+ module ActiveRecordExtension
3
+ extend ActiveSupport::Concern
4
+
5
+ def bounce(params=nil)
6
+ if params.present?
7
+ tap {|o| o.update_attributes(params) }
8
+ else
9
+ tap(&:save)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class Railtie < Rails::Railtie
2
+ config.before_initialize do
3
+ ActiveRecord::Base.send :include, Bounce::ActiveRecordExtension
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Bounce
2
+ VERSION = '0.0.1'
3
+ end
data/lib/bounce.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'rails'
2
+ require 'bounce/railtie'
3
+ require 'bounce/extension'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bounce
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Thomas Marino
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-04 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "\n\n `bounce` will save and return an active record object. This results in a nice refactor of update and create actions in your controllers. This works really well with `respond_with`.\n "
23
+ email: writejm@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - Rakefile
33
+ - LICENSE
34
+ - lib/bounce/extension.rb
35
+ - lib/bounce/railtie.rb
36
+ - lib/bounce/version.rb
37
+ - lib/bounce.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/johmas/bounce
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: bounce
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: bounce is a rails method that saves and returns an active record object. If you like skinny controllers, you'll love bounce.
72
+ test_files: []
73
+