before_actions 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +27 -58
  3. data/Rakefile +0 -0
  4. data/lib/before_actions/command.rb +0 -0
  5. data/lib/before_actions/controller.rb +0 -0
  6. data/lib/before_actions/engine.rb +0 -0
  7. data/lib/before_actions/version.rb +1 -1
  8. data/lib/before_actions.rb +0 -0
  9. data/lib/generators/before_actions/USAGE +0 -0
  10. data/lib/generators/before_actions/install_generator.rb +0 -0
  11. data/lib/generators/before_actions/templates/controller.rb +45 -17
  12. data/lib/tasks/before_actions_tasks.rake +0 -0
  13. data/test/before_actions_test.rb +0 -0
  14. data/test/dummy/README.rdoc +0 -0
  15. data/test/dummy/Rakefile +0 -0
  16. data/test/dummy/app/assets/javascripts/application.js +0 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +0 -0
  18. data/test/dummy/app/controllers/application_controller.rb +0 -0
  19. data/test/dummy/app/helpers/application_helper.rb +0 -0
  20. data/test/dummy/app/views/layouts/application.html.erb +0 -0
  21. data/test/dummy/bin/bundle +0 -0
  22. data/test/dummy/bin/rails +0 -0
  23. data/test/dummy/bin/rake +0 -0
  24. data/test/dummy/config/application.rb +0 -0
  25. data/test/dummy/config/boot.rb +0 -0
  26. data/test/dummy/config/database.yml +0 -0
  27. data/test/dummy/config/environment.rb +0 -0
  28. data/test/dummy/config/environments/development.rb +0 -0
  29. data/test/dummy/config/environments/production.rb +0 -0
  30. data/test/dummy/config/environments/test.rb +0 -0
  31. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -0
  32. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -0
  33. data/test/dummy/config/initializers/inflections.rb +0 -0
  34. data/test/dummy/config/initializers/mime_types.rb +0 -0
  35. data/test/dummy/config/initializers/secret_token.rb +0 -0
  36. data/test/dummy/config/initializers/session_store.rb +0 -0
  37. data/test/dummy/config/initializers/wrap_parameters.rb +0 -0
  38. data/test/dummy/config/locales/en.yml +0 -0
  39. data/test/dummy/config/routes.rb +0 -0
  40. data/test/dummy/config.ru +0 -0
  41. data/test/dummy/public/404.html +0 -0
  42. data/test/dummy/public/422.html +0 -0
  43. data/test/dummy/public/500.html +0 -0
  44. data/test/dummy/public/favicon.ico +0 -0
  45. data/test/integration/navigation_test.rb +0 -0
  46. data/test/test_helper.rb +0 -0
  47. metadata +20 -21
  48. data/MIT-LICENSE +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45023060a8c4e42aac286f003e5c8c19c1b3ca1e
4
- data.tar.gz: 6b64aed8bb12fdf0229d501c5d0ab815238ba747
3
+ metadata.gz: ea9d707f1d88575ff7beb6ee79a347f5284bf5b6
4
+ data.tar.gz: 914c0a5932b5b0081d41001e45e0904e0911bc9c
5
5
  SHA512:
6
- metadata.gz: c58e819bffab91b4579634046860c97ac562bfe5975ee2879cb7a2dd1043056d9866c9ac131c078f63dedca554d0cf88ceaad06b9e894221173260e6cee2f479
7
- data.tar.gz: 70bcb065a8700d1d1fc3697d2a7789a4cf1a0395813b3ad3c3a31fa361d781b4deb97bf86e46c6e8466b31b9c63314e6a29c9b6292749bddf88ab5fe3d48b3ea
6
+ metadata.gz: cd0cc56ec57da9eb2aedc71bed330b08ac9f17f249adc0b681ba85151e17f1598540373ded5ace62ff9aef8e6d8aaef433ec42c6563976ccff31d422c85759c7
7
+ data.tar.gz: fefc09e1cb6d87cb7d855f08f57275b656e76ddb97ffe3932a604719d9cc147fd93cb67dee8cea715d31cdc60067912d84c332d09b4108c18571bc27531123cc
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
- = BeforeActions {<img src="https://badge.fury.io/rb/before_actions.png" alt="Gem Version" />}[http://badge.fury.io/rb/before_actions]
1
+ = BeforeActions {<img src="https://badge.fury.io/rb/before_actions.png" alt="Gem Version" />}[http://badge.fury.io/rb/before_actions] {<img src="http://inch-ci.org/github/yakko/before_actions.png" alt="Inline docs" />}[http://inch-ci.org/github/yakko/before_actions] {<img src="https://gemnasium.com/yakko/before_actions.svg" alt="Dependency Status" />}[https://gemnasium.com/yakko/before_actions]
2
2
 
3
- Wiki[https://github.com/yakko/before_actions/wiki] | RubyGems[https://rubygems.org/gems/before_actions]
3
+ Wiki[https://github.com/before-actions-gem/before_actions/wiki] | RubyGems[https://rubygems.org/gems/before_actions]
4
4
 
5
5
  BeforeActions an elegant way of loading resorces in your restful controllers.
6
6
 
@@ -12,80 +12,49 @@ In <b>Rails 3</b> and <b>Rails 4</b>, add this to your Gemfile and run the +bund
12
12
 
13
13
  bundle
14
14
 
15
- Run this command to make all your new generated scaffold controllers come with a before_actions call by default
16
-
17
- rails g before_actions:install
18
-
19
15
  == Instructions
20
16
 
21
17
  == 1. Using the command
22
18
 
23
- {<img src="readme_images/method.png" alt="image" />}[https://github.com/yakko/before_actions]
24
-
25
- class CleanersController < ApplicationController
26
- before_action :define_cleaner
19
+ class ContactsController < ApplicationController
27
20
 
28
- private
29
- # Use callbacks to share common setup or constraints between actions.
30
- def define_cleaner
21
+ # load and authorize resources
22
+ before_actions do
23
+ # all actions
24
+ # actions { }
31
25
 
32
- before_actions do
33
- actions { # load your nested resource's parent here if you need one }
34
- actions(:index) { @cleaners = Cleaner.all }
35
- actions(:new) { @cleaner = Cleaner.new }
36
- actions(:create) { @cleaner = Cleaner.new(cleaner_params) }
37
- actions(:show, :edit, :update, :destroy) { @cleaner = Cleaner.find(params[:id]) }
38
- actions { # run your authorization logic here if you need one }
39
- end
40
-
41
- end
26
+ # list actions
27
+ actions(:index) { @contacts = Contact.all }
42
28
 
43
- end
29
+ # building actions
30
+ actions(:new) { @contact = Contact.new }
31
+ actions(:create) { @contact = Contact.new(contact_params) }
44
32
 
45
- == 2. Enjoy your clean controller
46
-
47
- {<img src="readme_images/clean_controller.png" alt="image" />}[https://github.com/yakko/before_actions]
33
+ # member actions, will raise a 404 if the model is not found
34
+ actions(:show, :edit, :update, :destroy) { @contact = Contact.find(params[:id]) }
48
35
 
36
+ # all actions
37
+ # actions { }
38
+ end
49
39
 
50
- == 3. Nested Routes
40
+ def contact_params
41
+ params.require(:contact).permit(:name)
42
+ end
51
43
 
52
- Given that
53
44
 
54
- Company has_many :clears
55
-
56
- {<img src="readme_images/nested.png" alt="image" />}[https://github.com/yakko/before_actions]
57
-
58
-
59
- == 4. Authorization made easy
45
+ == 2. Enjoy your clean controller
60
46
 
61
- {<img src="readme_images/authorization.png" alt="image" />}[https://github.com/yakko/before_actions]
47
+ {contacts_controller.rb}[https://github.com/before-actions-gem/before_actions/blob/master/readme_images/contacts_controller.rb]
62
48
 
63
- class CleanersController < ApplicationController
64
- before_action :define_cleaner
49
+ {<img src="readme_images/controller.jpg" alt="image" />}[https://github.com/before-actions-gem/before_actions]
65
50
 
66
- private
67
- # Use callbacks to share common setup or constraints between actions.
68
- def define_cleaner
69
51
 
70
- before_actions do
71
- actions { @company = Company.find(params[:company_id]) }
72
- actions(:index) { ... }
73
- actions(:new) { ... }
74
- actions(:create) { ... }
75
- actions(:show, :edit, :update, :destroy) { @cleaner = @company.cleaners.find(params[:id]) }
76
- actions do
77
- if @company.manager == current_user
78
- flash[:alert] = "You need to be the manager for #{@company.name} to access this area."
79
- redirect_to root_path
80
- end
81
- end
82
- end
83
-
84
- end
52
+ == 3. Nested Routes
85
53
 
86
- end
54
+ {<img src="readme_images/nested.png" alt="image" />}[https://github.com/before-actions-gem/before_actions]
87
55
 
88
56
 
89
57
 
58
+ == License
90
59
 
91
- This project rocks and uses MIT-LICENSE.
60
+ Before Actions is released under the {MIT License}[http://www.opensource.org/licenses/MIT].
data/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module BeforeActions
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
File without changes
File without changes
File without changes
@@ -16,54 +16,82 @@ class <%= controller_class_name %>Controller < ApplicationController
16
16
  end
17
17
 
18
18
  # GET <%= route_url %>
19
+ # GET <%= route_url %>.json
19
20
  def index
21
+ respond_to do |format|
22
+ format.html # index.html.erb
23
+ format.json { render json: <%= "@#{plural_table_name}" %> }
24
+ end
20
25
  end
21
26
 
22
- # GET <%= route_url %>/1
23
- def show
24
- end
27
+
25
28
 
26
29
  # GET <%= route_url %>/new
27
30
  def new
28
31
  end
29
32
 
33
+ # GET <%= route_url %>/1
34
+ # GET <%= route_url %>/1.json
35
+ def show
36
+ respond_to do |format|
37
+ format.html # show.html.erb
38
+ format.json { render json: <%= "@#{singular_table_name}" %> }
39
+ end
40
+ end
41
+
30
42
  # GET <%= route_url %>/1/edit
31
43
  def edit
32
44
  end
33
45
 
46
+
47
+
34
48
  # POST <%= route_url %>
49
+ # POST <%= route_url %>.json
35
50
  def create
36
- if @<%= orm_instance.save %>
37
- redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
38
- else
39
- render action: 'new'
51
+ respond_to do |format|
52
+ if @<%= orm_instance.save %>
53
+ format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
54
+ format.json { render json: <%= "@#{singular_table_name}" %>, status: :created }
55
+ else
56
+ format.html { render action: 'new' }
57
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
58
+ end
40
59
  end
41
60
  end
42
61
 
43
62
  # PATCH/PUT <%= route_url %>/1
63
+ # PATCH/PUT <%= route_url %>/1.json
44
64
  def update
45
- if @<%= orm_instance.update("#{singular_table_name}_params") %>
46
- redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
47
- else
48
- render action: 'edit'
65
+ respond_to do |format|
66
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
67
+ format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
68
+ format.json { head :no_content }
69
+ else
70
+ format.html { render action: 'edit' }
71
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
72
+ end
49
73
  end
50
74
  end
51
75
 
76
+ # DELETE <%= route_url %>/1
52
77
  # DELETE <%= route_url %>/1
53
78
  def destroy
54
- @<%= orm_instance.destroy %>
55
- redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
79
+ respond_to do |format|
80
+ if @<%= orm_instance.destroy %>
81
+ format.html { redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> }
82
+ format.json { head :no_content }
83
+ else
84
+ format.html { render action: 'edit' }
85
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
86
+ end
87
+ end
56
88
  end
57
89
 
58
90
  private
59
91
 
60
92
  # Only allow a trusted parameter "white list" through.
61
93
  def <%= "#{singular_table_name}_params" %>
62
- <%- if attributes_names.empty? -%>
63
- params[<%= ":#{singular_table_name}" %>]
64
- <%- else -%>
65
94
  params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
66
- <%- end -%>
67
95
  end
68
96
  end
69
97
  <% end -%>
File without changes
File without changes
File without changes
data/test/dummy/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/dummy/bin/rails CHANGED
File without changes
data/test/dummy/bin/rake CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/dummy/config.ru CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/test_helper.rb CHANGED
File without changes
metadata CHANGED
@@ -1,50 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: before_actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pinto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Loading all your resources before the action not only makes your code
28
- cleaner, but also makes authorization and nested routes easier.
27
+ description: Organize your controllers by grouping your before and after filters.
29
28
  email:
30
- - james@rubyfactory.net
29
+ - tjamespinto@gmail.com
31
30
  executables: []
32
31
  extensions: []
33
32
  extra_rdoc_files: []
34
33
  files:
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/before_actions.rb
35
37
  - lib/before_actions/command.rb
36
38
  - lib/before_actions/controller.rb
37
39
  - lib/before_actions/engine.rb
38
40
  - lib/before_actions/version.rb
39
- - lib/before_actions.rb
41
+ - lib/generators/before_actions/USAGE
40
42
  - lib/generators/before_actions/install_generator.rb
41
43
  - lib/generators/before_actions/templates/controller.rb
42
- - lib/generators/before_actions/USAGE
43
44
  - lib/tasks/before_actions_tasks.rake
44
- - MIT-LICENSE
45
- - Rakefile
46
- - README.rdoc
47
45
  - test/before_actions_test.rb
46
+ - test/dummy/README.rdoc
47
+ - test/dummy/Rakefile
48
48
  - test/dummy/app/assets/javascripts/application.js
49
49
  - test/dummy/app/assets/stylesheets/application.css
50
50
  - test/dummy/app/controllers/application_controller.rb
@@ -53,6 +53,7 @@ files:
53
53
  - test/dummy/bin/bundle
54
54
  - test/dummy/bin/rails
55
55
  - test/dummy/bin/rake
56
+ - test/dummy/config.ru
56
57
  - test/dummy/config/application.rb
57
58
  - test/dummy/config/boot.rb
58
59
  - test/dummy/config/database.yml
@@ -69,17 +70,15 @@ files:
69
70
  - test/dummy/config/initializers/wrap_parameters.rb
70
71
  - test/dummy/config/locales/en.yml
71
72
  - test/dummy/config/routes.rb
72
- - test/dummy/config.ru
73
73
  - test/dummy/public/404.html
74
74
  - test/dummy/public/422.html
75
75
  - test/dummy/public/500.html
76
76
  - test/dummy/public/favicon.ico
77
- - test/dummy/Rakefile
78
- - test/dummy/README.rdoc
79
77
  - test/integration/navigation_test.rb
80
78
  - test/test_helper.rb
81
- homepage: https://github.com/yakko/before_actions
82
- licenses: []
79
+ homepage: https://github.com/before-actions-gem/before_actions
80
+ licenses:
81
+ - MIT
83
82
  metadata: {}
84
83
  post_install_message:
85
84
  rdoc_options: []
@@ -87,20 +86,20 @@ require_paths:
87
86
  - lib
88
87
  required_ruby_version: !ruby/object:Gem::Requirement
89
88
  requirements:
90
- - - '>='
89
+ - - ">="
91
90
  - !ruby/object:Gem::Version
92
91
  version: '0'
93
92
  required_rubygems_version: !ruby/object:Gem::Requirement
94
93
  requirements:
95
- - - '>='
94
+ - - ">="
96
95
  - !ruby/object:Gem::Version
97
96
  version: '0'
98
97
  requirements: []
99
98
  rubyforge_project:
100
- rubygems_version: 2.0.3
99
+ rubygems_version: 2.2.2
101
100
  signing_key:
102
101
  specification_version: 4
103
- summary: Simplified solution for restful resources in Rails.
102
+ summary: Rails Gem to organize your controllres
104
103
  test_files:
105
104
  - test/before_actions_test.rb
106
105
  - test/dummy/app/assets/javascripts/application.js
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2013 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.