Class: Tasker::Generators::AuthenticatorGenerator

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

Defined Under Namespace

Classes: UsageInstructionsFormatter

Instance Method Summary collapse

Instance Method Details

#create_authenticator_fileObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/tasker/authenticator_generator.rb', line 24

def create_authenticator_file
  ensure_directory_exists(options[:directory])

  case options[:type].downcase
  when 'jwt'
    template 'jwt_authenticator.rb.erb', File.join(options[:directory], "#{file_name}_authenticator.rb")
  when 'devise'
    template 'devise_authenticator.rb.erb', File.join(options[:directory], "#{file_name}_authenticator.rb")
  when 'api_token'
    template 'api_token_authenticator.rb.erb', File.join(options[:directory], "#{file_name}_authenticator.rb")
  when 'omniauth'
    template 'omniauth_authenticator.rb.erb', File.join(options[:directory], "#{file_name}_authenticator.rb")
  else
    template 'custom_authenticator.rb.erb', File.join(options[:directory], "#{file_name}_authenticator.rb")
  end
end

#create_spec_fileObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/tasker/authenticator_generator.rb', line 41

def create_spec_file
  return unless options[:with_spec] && defined?(RSpec)

  ensure_directory_exists('spec/tasker/authenticators')

  case options[:type].downcase
  when 'jwt'
    template 'jwt_authenticator_spec.rb.erb',
             File.join('spec/tasker/authenticators', "#{file_name}_authenticator_spec.rb")
  when 'devise'
    template 'devise_authenticator_spec.rb.erb',
             File.join('spec/tasker/authenticators', "#{file_name}_authenticator_spec.rb")
  when 'api_token'
    template 'api_token_authenticator_spec.rb.erb',
             File.join('spec/tasker/authenticators', "#{file_name}_authenticator_spec.rb")
  when 'omniauth'
    template 'omniauth_authenticator_spec.rb.erb',
             File.join('spec/tasker/authenticators', "#{file_name}_authenticator_spec.rb")
  else
    template 'custom_authenticator_spec.rb.erb',
             File.join('spec/tasker/authenticators', "#{file_name}_authenticator_spec.rb")
  end
end

#show_usage_instructionsObject



65
66
67
# File 'lib/generators/tasker/authenticator_generator.rb', line 65

def show_usage_instructions
  UsageInstructionsFormatter.display(self)
end