Sha256: 4dc5e61940e4a6cc5635b4d5efac6ae43b701509bbfb8e8e3a57d0fd20e37d16
Contents?: true
Size: 1.32 KB
Versions: 6
Compression:
Stored size: 1.32 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? user_permissions? end def update? user_permissions? end def delete? admin_permissions? end private def user_permissions? @user.master? or @user.admin? or @user.user? end def admin_permissions? @user.master? or @user.admin? end end EOS end puts Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }] file_path rescue StandardError => e raise StandardError, e end end end end
Version data entries
6 entries across 6 versions & 1 rubygems