pundit_scaffold_generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f768b2a77b5f28b046055d2518e604fde5bcd0c2ddc239fe7a849b7a80b6abb
4
+ data.tar.gz: 05440a83f2c85b190d11d1a6ffe914387e5a184f8cf458e355d1e477234d0628
5
+ SHA512:
6
+ metadata.gz: c072752483ba23786a210dcafcbcb4af2974757027f8e24b0fcce804d6d73ff9ac05b3fd3d83f4722f3ae04a4e5e7988c5a25f6a921ec3d6292578236a23f674
7
+ data.tar.gz: 26cafb88d96a4823d7fe84021c6060faa60be8af3c40d75f7d6bcbc0335052d0130d91ae3d6a9a9ef458e881f3510a1cc0b0cccb66f37e53be95566636fdbb43
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pundit_scaffold_generator.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pundit_scaffold_generator (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ rake (13.1.0)
11
+ rspec (3.12.0)
12
+ rspec-core (~> 3.12.0)
13
+ rspec-expectations (~> 3.12.0)
14
+ rspec-mocks (~> 3.12.0)
15
+ rspec-core (3.12.2)
16
+ rspec-support (~> 3.12.0)
17
+ rspec-expectations (3.12.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.12.0)
20
+ rspec-mocks (3.12.6)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.12.0)
23
+ rspec-support (3.12.1)
24
+
25
+ PLATFORMS
26
+ x86_64-linux
27
+
28
+ DEPENDENCIES
29
+ pundit_scaffold_generator!
30
+ rake (~> 13.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.3.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Dmitry Kulikov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # PunditScaffoldGenerator
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pundit_scaffold_generator`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dima4p/pundit_scaffold_generator.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rspec
4
+ #module Generators
5
+ class PolicyGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def create_policy_spec
9
+ template "policy_spec.rb", File.join("spec/policies", class_path, "#{file_name}_policy_spec.rb")
10
+ end
11
+ end
12
+ #end
13
+ end
@@ -0,0 +1,53 @@
1
+ require '<%= File.exist?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
2
+
3
+ RSpec.describe <%= class_name %>Policy, type: :policy do
4
+ subject(:policy) { described_class }
5
+ let(:allow) { permit user, <%= file_name %> }
6
+ <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_bot -%>
7
+ let(:user) { create :user }
8
+ let(:<%= file_name %>) {create :<%= file_name %>}
9
+ <% else -%>
10
+ let(:user) { User.new }
11
+ let(:<%= file_name %>) {<%= class_name %>.new }
12
+ <% end -%>
13
+
14
+ permissions :index? do
15
+ it 'permits' do
16
+ is_expected.to allow
17
+ end
18
+ end
19
+
20
+ permissions :show? do
21
+ it 'permits' do
22
+ is_expected.to allow
23
+ end
24
+ end
25
+
26
+ permissions :create? do
27
+ it 'permits' do
28
+ is_expected.to allow
29
+ end
30
+ end
31
+
32
+ permissions :update? do
33
+ it 'permits' do
34
+ is_expected.to allow
35
+ end
36
+ end
37
+
38
+ permissions :destroy? do
39
+ it 'permits' do
40
+ is_expected.to allow
41
+ end
42
+ end
43
+
44
+ context "::scope" do
45
+ subject(:policy_scope) do
46
+ described_class::Scope.new(user, <%= class_name %>).resolve
47
+ end
48
+
49
+ it 'shows all records' do
50
+ is_expected.to eq <%= class_name %>.all
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ module PolicyGenerator
2
+ module Generators
3
+ class ScaffoldGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ puts "PolicyGenerator::Generators::ScaffoldGenerator"
6
+
7
+ def create_policy
8
+ template "policy.rb", File.join("app/policies", class_path, "#{file_name}_policy.rb")
9
+ end
10
+
11
+ hook_for :test_framework, as: :policy
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Policy < ApplicationPolicy
3
+ def index?
4
+ super
5
+ end
6
+
7
+ def create?
8
+ super
9
+ end
10
+
11
+ def show?
12
+ super
13
+ end
14
+
15
+ def update?
16
+ super
17
+ end
18
+
19
+ def destroy?
20
+ super
21
+ end
22
+
23
+ class Scope < Scope
24
+ # NOTE: Be explicit about which records you allow access to!
25
+ def resolve
26
+ scope.all
27
+ end
28
+ end
29
+ end
30
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ require 'rails/generators/rails/scaffold/scaffold_generator'
2
+
3
+ class Rails::Generators::ScaffoldGenerator
4
+ class_option :policy_generator, desc: 'Internalization Engine',
5
+ default: 'policy_generator'
6
+ hook_for :policy_generator, required: true
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PunditScaffoldGenerator
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pundit_scaffold_generator/version"
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pundit_scaffold_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Kulikov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ When your project uses pundit gem for authorization this gem generates
15
+ the code for /policies and /spec/policies
16
+ email:
17
+ - dima@koulikoff.de
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rspec"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/generators/policy_generator/rspec/rspec_generator.rb
29
+ - lib/generators/policy_generator/rspec/templates/policy_spec.rb
30
+ - lib/generators/policy_generator/scaffold/scaffold_generator.rb
31
+ - lib/generators/policy_generator/scaffold/templates/policy.rb
32
+ - lib/generators/scaffold/scaffold_generator.rb
33
+ - lib/pundit_scaffold_generator.rb
34
+ - lib/pundit_scaffold_generator/version.rb
35
+ homepage: https://github.com/dima4p/pundit_scaffold_generator
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/dima4p/pundit_scaffold_generator
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.4
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: the code for /policies and /spec/policies if pundit is used
59
+ test_files: []