controller_resources 0.0.5 → 0.0.6

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +7 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +6 -3
  6. data/README.md +107 -13
  7. data/Rakefile +15 -1
  8. data/bin/cc-tddium-post-worker +16 -0
  9. data/bin/erubis +16 -0
  10. data/bin/htmldiff +16 -0
  11. data/bin/ldiff +16 -0
  12. data/bin/nokogiri +16 -0
  13. data/bin/rackup +16 -0
  14. data/bin/rails +12 -8
  15. data/bin/rake +16 -0
  16. data/bin/rspec +16 -0
  17. data/bin/rubocop +16 -0
  18. data/bin/ruby-parse +16 -0
  19. data/bin/ruby-rewrite +16 -0
  20. data/bin/sprockets +16 -0
  21. data/bin/thor +16 -0
  22. data/controller_resources.gemspec +14 -6
  23. data/lib/controller_resources/engine.rb +1 -0
  24. data/lib/controller_resources/extension.rb +65 -63
  25. data/lib/controller_resources/resource.rb +99 -0
  26. data/lib/controller_resources/version.rb +2 -1
  27. data/lib/controller_resources.rb +13 -4
  28. data/spec/dummy/app/assets/javascripts/posts.js +2 -0
  29. data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
  30. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  31. data/spec/dummy/app/controllers/posts_controller.rb +44 -0
  32. data/spec/dummy/app/helpers/posts_helper.rb +2 -0
  33. data/spec/dummy/app/models/post.rb +2 -0
  34. data/spec/dummy/app/views/posts/_form.html.erb +29 -0
  35. data/spec/dummy/app/views/posts/edit.html.erb +6 -0
  36. data/spec/dummy/app/views/posts/index.html.erb +31 -0
  37. data/spec/dummy/app/views/posts/new.html.erb +5 -0
  38. data/spec/dummy/app/views/posts/show.html.erb +19 -0
  39. data/spec/dummy/config/application.rb +2 -0
  40. data/spec/dummy/config/environments/test.rb +1 -1
  41. data/spec/dummy/config/routes.rb +1 -2
  42. data/spec/dummy/db/migrate/20150614211054_create_posts.rb +10 -0
  43. data/spec/dummy/db/schema.rb +26 -0
  44. data/spec/dummy/test/controllers/posts_controller_test.rb +49 -0
  45. data/spec/dummy/test/fixtures/posts.yml +11 -0
  46. data/spec/dummy/test/models/post_test.rb +7 -0
  47. data/spec/integration/navigation_spec.rb +1 -1
  48. data/spec/lib/controller_resources/extension_spec.rb +42 -0
  49. data/spec/lib/controller_resources/resource_spec.rb +46 -0
  50. data/spec/spec_helper.rb +16 -14
  51. metadata +98 -26
  52. data/lib/controller_resources/responder.rb +0 -0
  53. data/lib/generators/controller_resources/USAGE +0 -8
  54. data/lib/generators/controller_resources/install_generator.rb +0 -16
  55. data/spec/controller_resources/extension_spec.rb +0 -32
  56. data/spec/generators/controller_resources/install_generator_spec.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6641d78693a54de498d10f9d1d53243bcaf1997d
4
- data.tar.gz: 180ca43f6043f5a50a094e167cf399da6010b57c
3
+ metadata.gz: 1813e22346789043275cf46f1a6e554396d2b454
4
+ data.tar.gz: 4e2e6622d6c1cb24d07fac8ef82c6c373130ddac
5
5
  SHA512:
6
- metadata.gz: 08d0bc4c3a24e6110df16fb9210d4def5884f3cfaee4254ee2ca99367ad0dccdf4ec897a72944daa90c003a3866cffaaa592e5ea5267f68960e71b00afc2e730
7
- data.tar.gz: 0e968d80f3d199f1ed5b800e61d2190c3e1fbd226ced05a59e0ce4eca736772f39090fa118a75564e0bf4604bb078b97423f10f3da7d5a63e08c047a5463571f
6
+ metadata.gz: bb9fa68805b138bf1c1b7d0efaaa134e46c5b75864e8822b99ebe97f14027a011c1acf287a763b00c0dc843cf85f981e4fbd61c44c2aec2bb0ea5c6659fa6ff3
7
+ data.tar.gz: 42cc040fb18486bf5df3a8b4b7cfc02ffb2267bc9fd6cab812de9f240d3538ea32f609c7f3c1cf5a996744c85a7729b3e367de89c7860e4e4f5e63f0aba5ace0
data/.gitignore CHANGED
@@ -13,3 +13,6 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  /spec/dummy/log/*.log
16
+ /vendor
17
+ .env
18
+ tags
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ Exclude:
3
+ - spec/dummy/**/*
4
+ - vendor/**/*
5
+ - bin/**/*
6
+ Metrics/AbcSize:
7
+ Max: 32
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.2.2
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
1
  language: ruby
2
- rvm: 2.1.5
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.2
3
6
  cache: bundle
4
- before_script: bundle exec rake db:setup
5
- script: bundle exec rspec
7
+ before_script: ./bin/rake db
8
+ script: ./bin/rake test
6
9
  addons:
7
10
  codeclimate:
8
11
  repo_token:
data/README.md CHANGED
@@ -4,14 +4,39 @@
4
4
  [![Code Climate](https://codeclimate.com/github/tubbo/controller_resources/badges/gpa.svg)](https://codeclimate.com/github/tubbo/controller_resources)
5
5
  [![Test Coverage](https://codeclimate.com/github/tubbo/controller_resources/badges/coverage.svg)](https://codeclimate.com/github/tubbo/controller_resources)
6
6
 
7
- A Rails engine that unites DecentExposure, StrongParameters, Devise (if
8
- installed) and Draper (if installed) to provide one hell of an awesome
9
- controller DSL.
7
+ A Rails engine providing a common DSL for fetching model resources in
8
+ the controller and view layers. It leverages
9
+ [DecentExposure][de],[StrongParameters][sp] and assumes an
10
+ [ActiveRecord][ar]-like DSL for querying model objects.
11
+ ControllerResources does not assume any part of your stack, instead
12
+ providing generic tools and extensions to ActionController which allow
13
+ you to use the fetched resources however you want.
10
14
 
11
- ## Features
15
+ ```ruby
16
+ resource :post do
17
+ search :title, :category
18
+ modify :title, :category, :body, :is_published
19
+ end
20
+ ```
21
+
22
+ ...and not have to worry about where the `posts` and `post` methods come
23
+ from. If you're used to working with DecentExposure, you'll know that
24
+ we're just using the `expose` macro to set up these resources, and using
25
+ the `resource` macro to populate what we expose and additionally what
26
+ parameters to pass through.
27
+
28
+ You can establish DecentExposure configuration with the `resource` block
29
+ by calling methods which do not exist on the Resource. All of these
30
+ methods are passed down to DecentExposure:
12
31
 
13
- - Provides a common DSL for describing strong parameters as well as
14
- rules for DecentExposure and response types (default: html,json)
32
+ ```ruby
33
+ expose :post, param: :post_id
34
+ resource :comment do
35
+ ancestor :post
36
+ search :body
37
+ modify :body, :user_id
38
+ end
39
+ ```
15
40
 
16
41
  ## Installation
17
42
 
@@ -21,10 +46,22 @@ Add this line to your application's Gemfile:
21
46
  gem 'controller_resources'
22
47
  ```
23
48
 
24
- Then run the following generator to generate the locale file:
49
+ Then run the following generator to generate the locale files for
50
+ Responders:
25
51
 
26
52
  ```bash
27
- $ rails generate controller_resources:install
53
+ $ rails generate responders:install
54
+ ```
55
+
56
+ This will also insert Responders into your `ApplicationController`. If
57
+ you do not want this, be sure to include the following code in a base
58
+ controller somewhere...this is the best way for `ControllerResources` to
59
+ function:
60
+
61
+ ```ruby
62
+ class ApplicationController < ActionController::Base
63
+ responders :flash, :http_cache
64
+ end
28
65
  ```
29
66
 
30
67
  ## Usage
@@ -62,10 +99,67 @@ access the model objects passed down into the template:
62
99
  <%= user.name %>
63
100
  ```
64
101
 
102
+ <<<<<<< HEAD
103
+ You can also use some given helpers for establishing authorization logic
104
+ in ApplicationController. Since `ControllerResources` is included by
105
+ default, you can use the given `current_resource` method to tell Pundit
106
+ (for example) which policy to use in authorization:
107
+
108
+ ```ruby
109
+ class ApplicationController < ActionController::Base
110
+ before_action :authenticate_user!
111
+ before_action :authorize_user!
112
+
113
+ rescue_from Pundit::NotAuthorizedError, with: :forbidden
114
+
115
+ def forbidden
116
+ render 'forbidden', status: :forbidden
117
+ end
118
+
119
+ private
120
+
121
+ def authorize_user!
122
+ authorize current_user, current_resource, current_action
123
+ end
124
+
125
+ def current_action
126
+ :"#{action_name}?"
127
+ end
128
+ end
129
+ ```
130
+
131
+ This `current_resource` method is populated by the given configured
132
+ Resource object, which will attempt to classify its `model_name` and
133
+ provide a class constant that can be used here. In the
134
+ `PostsController#show` action, for example, that call to `authorize` would be
135
+ partially expanded like this:
136
+
137
+ ```ruby
138
+ authorize current_user, Post, :show?
139
+ ```
140
+
141
+ (where `current_user` is the authenticated User found by Devise)
142
+
143
+ While ControllerResources doesn't provide authorization or
144
+ authentication helpers, it does provide the necessary methods to aid
145
+ your own authorization and authentication frameworks in their job.
146
+
65
147
  ## Contributing
66
148
 
67
- 1. Fork it ( https://github.com/tubbo/controller_resources/fork )
68
- 2. Create your feature branch (`git checkout -b my-new-feature`)
69
- 3. Commit your changes (`git commit -am 'Add some feature'`)
70
- 4. Push to the branch (`git push origin my-new-feature`)
71
- 5. Create a new Pull Request
149
+ Contributions to `ControllerResources` may be made using GitHub pull
150
+ requests. You must include accompanying tests, and all tests must pass
151
+ for any contribution to be considered.
152
+
153
+ To run tests:
154
+
155
+ ```bash
156
+ $ rake test
157
+ ```
158
+
159
+ This will also use Rubocop to lint-check your code so it adheres to our
160
+ style guide.
161
+
162
+ [de]: https://github.com/hashrocket/decent_exposure
163
+ [rp]: https://github.com/plataformatec/responders
164
+ [sp]: https://github.com/rails/strong_parameters
165
+
data/Rakefile CHANGED
@@ -1,2 +1,16 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
2
5
 
6
+ desc 'Set up the test database for the dummy app'
7
+ task :db do
8
+ sh 'cd spec/dummy && bundle exec rake db:create db:migrate'
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new :spec
12
+
13
+ RuboCop::RakeTask.new :lint
14
+
15
+ desc 'Run Rubocop lint checks and RSpec code examples'
16
+ task test: %w(lint spec)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'cc-tddium-post-worker' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('codeclimate-test-reporter', 'cc-tddium-post-worker')
data/bin/erubis ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'erubis' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('erubis', 'erubis')
data/bin/htmldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'htmldiff')
data/bin/ldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/nokogiri ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'nokogiri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('nokogiri', 'nokogiri')
data/bin/rackup ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rackup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rack', 'rackup')
data/bin/rails CHANGED
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rails' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
3
8
 
4
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
- ENGINE_PATH = File.expand_path('../../lib/controller_resources/engine', __FILE__)
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
6
12
 
7
- # Set up gems listed in the Gemfile.
8
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
13
+ require 'rubygems'
14
+ require 'bundler/setup'
10
15
 
11
- require 'rails/all'
12
- require 'rails/engine/commands'
16
+ load Gem.bin_path('railties', 'rails')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/ruby-parse ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ruby-parse' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('parser', 'ruby-parse')
data/bin/ruby-rewrite ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ruby-rewrite' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('parser', 'ruby-rewrite')
data/bin/sprockets ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'sprockets' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sprockets', 'sprockets')
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('thor', 'thor')
@@ -8,24 +8,32 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ControllerResources::VERSION
9
9
  spec.authors = ['Tom Scott']
10
10
  spec.email = ['tubbo@psychedeli.ca']
11
- spec.summary = %q{A "glue" for decent_exposure, responders, draper and strong_params}
12
- spec.description = %q{A "glue" for decent_exposure, responders, draper and strong_params}
11
+ spec.summary = '
12
+ A controller DSL for Rails that allows you to easily and quickly
13
+ define both singular and collection model resources that can be
14
+ operated on within the controller.
15
+ '.strip
16
+ spec.description = spec.summary + '
17
+ Attempts to DRY up most of the boilerplate code at the top of
18
+ each controller used to set up its state.
19
+ '.strip
13
20
  spec.homepage = 'https://github.com/tubbo/controller_resources'
14
21
  spec.license = 'MIT'
15
22
 
16
23
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
25
  spec.test_files = spec.files.grep(%r{^|spec/})
19
26
  spec.require_paths = ['lib']
20
27
 
21
- spec.add_development_dependency 'bundler', '~> 1.7'
22
- spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'rake'
23
30
  spec.add_development_dependency 'rspec', '~> 3'
24
31
  spec.add_development_dependency 'pg'
25
32
  spec.add_development_dependency 'generator_spec'
26
33
  spec.add_development_dependency 'codeclimate-test-reporter'
34
+ spec.add_development_dependency 'rubocop'
27
35
 
28
- spec.add_dependency 'rails', '>= 4.0.0'
36
+ spec.add_dependency 'rails'
29
37
  spec.add_dependency 'decent_exposure'
30
38
  spec.add_dependency 'responders'
31
39
  end
@@ -1,4 +1,5 @@
1
1
  module ControllerResources
2
+ # Extensions for the including Rails app.
2
3
  class Engine < ::Rails::Engine
3
4
  isolate_namespace ControllerResources
4
5