Sha256: 3e1dcd9a812f0443e1d63802e7015697e364b6909c6677b5c61c7c6b81f50c13

Contents?: true

Size: 1.12 KB

Versions: 138

Compression:

Stored size: 1.12 KB

Contents

module Souls
  class Generate < Thor
    desc "policy_rbs [CLASS_NAME]", "Generate Policy RBS"
    def policy_rbs(class_name)
      file_path = ""
      Dir.chdir(Souls.get_mother_path.to_s) do
        file_dir = "./sig/api/app/graphql/policies/"
        FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
        singularized_class_name = class_name.underscore.singularize
        file_path = "#{file_dir}#{singularized_class_name}_policy.rbs"
        File.open(file_path, "w") do |f|
          f.write(<<~TEXT)
            class #{singularized_class_name.camelize}Policy
              @user: untyped

              def show?: -> true
              def index?: -> true
              def create?: -> bool
              def update?: -> bool
              def delete?: -> bool

              private
              def user_permissions?: -> untyped
              def admin_permissions?: -> untyped
            end
          TEXT
        end
        puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
      end
      file_path
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end
  end
end

Version data entries

138 entries across 138 versions & 1 rubygems

Version Path
souls-0.61.3 lib/souls/cli/generate/policy_rbs.rb
souls-0.61.2 lib/souls/cli/generate/policy_rbs.rb
souls-0.61.1 lib/souls/cli/generate/policy_rbs.rb
souls-0.61.0 lib/souls/cli/generate/policy_rbs.rb
souls-0.60.3 lib/souls/api/generate/policy_rbs.rb
souls-0.60.2 lib/souls/api/generate/policy_rbs.rb
souls-0.60.1 lib/souls/api/generate/policy_rbs.rb
souls-0.60.0 lib/souls/api/generate/policy_rbs.rb
souls-0.59.2 lib/souls/api/generate/policy_rbs.rb
souls-0.59.1 lib/souls/api/generate/policy_rbs.rb
souls-0.59.0 lib/souls/api/generate/policy_rbs.rb
souls-0.58.3 lib/souls/api/generate/policy_rbs.rb
souls-0.58.2 lib/souls/api/generate/policy_rbs.rb
souls-0.58.1 lib/souls/api/generate/policy_rbs.rb
souls-0.58.0 lib/souls/api/generate/policy_rbs.rb
souls-0.57.1 lib/souls/api/generate/policy_rbs.rb
souls-0.57.0 lib/souls/api/generate/policy_rbs.rb
souls-0.56.4 lib/souls/api/generate/policy_rbs.rb