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-1.7.1 lib/souls/cli/generate/policy_rbs.rb
souls-1.7.0 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.15 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.14 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.13 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.12 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.11 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.10 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.9 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.8 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.7 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.6 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.5 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.4 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.3 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.2 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.1 lib/souls/cli/generate/policy_rbs.rb
souls-1.6.0 lib/souls/cli/generate/policy_rbs.rb
souls-1.5.7 lib/souls/cli/generate/policy_rbs.rb
souls-1.5.6 lib/souls/cli/generate/policy_rbs.rb