Sha256: 74e7819620a733b86a27ef538b549250f6000a7fac85665a925ae2a4ce6ad19c

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

Dir["#{__dir__}/lib/souls/generate/*.rb"].each { |f| require_relative f.gsub("./lib/souls", ".")}
require_relative "./generate/rspec_policy"

module Souls
  module Generate
    def self.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"
      File.open(file_path, "w") do |f|
        f.write <<~EOS
          class #{class_name.camelize}Policy < ApplicationPolicy
            def show?
              admin_permissions?
            end

            def index?
              admin_permissions?
            end

            def create?
              admin_permissions?
            end

            def update?
              admin_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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
souls-0.20.9 lib/souls/generate.rb