Sha256: a1084822f38e39c0f9bbcbc258071b6c239403ac5565ebf3cfd04a7b77b71f4a

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

module Souls
  module Generate
    class << self
      ## Generate Policy
      def policy class_name: "souls"
        dir_name = "./app/policies"
        FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
        file_path = "#{dir_name}/#{class_name.singularize}_policy.rb"
        return "Policy already exist! #{file_path}" if File.exist? file_path
        File.open(file_path, "w") do |f|
          f.write <<~EOS
            class #{class_name.camelize}Policy < ApplicationPolicy
              def show?
                true
              end

              def index?
                true
              end

              def create?
                staff_permissions?
              end

              def update?
                staff_permissions?
              end

              def delete?
                admin_permissions?
              end

              private

              def staff_permissions?
                @user.master? or @user.admin? or @user.staff?
              end

              def admin_permissions?
                @user.master? or @user.admin?
              end
            end
          EOS
        end
        file_path
      rescue StandardError => error
        puts "method error"
        puts error.backtrace
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
souls-0.22.1 lib/souls/generate/policy.rb
souls-0.22.0 lib/souls/generate/policy.rb
souls-0.21.9 lib/souls/generate/policy.rb
souls-0.21.8 lib/souls/generate/policy.rb
souls-0.21.7 lib/souls/generate/policy.rb
souls-0.21.6 lib/souls/generate/policy.rb
souls-0.21.5 lib/souls/generate/policy.rb
souls-0.21.4 lib/souls/generate/policy.rb
souls-0.21.3 lib/souls/generate/policy.rb
souls-0.21.2 lib/souls/generate/policy.rb
souls-0.21.1 lib/souls/generate/policy.rb