Class: Tasker::Generators::AuthorizationCoordinatorGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/tasker/authorization_coordinator_generator.rb

Overview

Rails generator for creating authorization coordinators

This generator creates authorization coordinator classes that inherit from Tasker::Authorization::BaseCoordinator and implement the authorization interface for different scenarios.

Examples:

Basic usage

rails generate tasker:authorization_coordinator CompanyAuth
rails generate tasker:authorization_coordinator TeamAuth --user-class=Team

Instance Method Summary collapse

Instance Method Details

#create_coordinator_classObject

Generate the authorization coordinator class



38
39
40
41
42
43
44
# File 'lib/generators/tasker/authorization_coordinator_generator.rb', line 38

def create_coordinator_class
  @coordinator_class_name = coordinator_class_name
  @user_class_name = user_class_name

  template 'authorization_coordinator.rb.erb',
           File.join(options[:directory], "#{file_name}_coordinator.rb")
end

#create_spec_fileObject

Generate the spec file if requested



47
48
49
50
51
52
53
54
55
# File 'lib/generators/tasker/authorization_coordinator_generator.rb', line 47

def create_spec_file
  return unless options[:with_spec]

  @coordinator_class_name = coordinator_class_name
  @user_class_name = user_class_name

  template 'authorization_coordinator_spec.rb.erb',
           File.join('spec', options[:directory].sub('app/', ''), "#{file_name}_coordinator_spec.rb")
end

Print usage instructions



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/generators/tasker/authorization_coordinator_generator.rb', line 58

def print_instructions
  say "\n#{set_color('Authorization Coordinator Generated!', :green)}"
  say set_color('=' * 50, :green)

  say "\nGenerated files:"
  say "  #{set_color("#{options[:directory]}/#{file_name}_coordinator.rb", :cyan)} - Coordinator class"
  if options[:with_spec]
    say "  #{set_color("spec/#{options[:directory].sub('app/', '')}/#{file_name}_coordinator_spec.rb",
                       :cyan)} - Test file"
  end

  say "\nNext steps:"
  say '1. Configure Tasker to use your coordinator:'
  say coordinator_configuration_example

  say "\n2. Ensure your User model includes the Authorizable concern:"
  say user_model_example

  say "\n3. Customize the authorization logic in your coordinator"
  say "\n4. Run the tests to verify everything works:"
  say "   #{set_color(
    "bundle exec rspec spec/#{options[:directory].sub('app/', '')}/#{file_name}_coordinator_spec.rb", :yellow
  )}"

  say "\nFor more information, see the Tasker authentication guide:"
  say "  #{set_color('docs/AUTH.md', :cyan)}"
end