Class: M365ActiveStorage::Generators::CheckGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/m365_active_storage/check/check_generator.rb

Overview

init the m365 active storage gem

Instance Method Summary collapse

Instance Method Details

#check_for_m365_credentialsObject

Validate m365 credentials and connectivity by making a test API call to Microsoft Graph



14
15
16
17
18
19
20
21
22
# File 'lib/generators/m365_active_storage/check/check_generator.rb', line 14

def check_for_m365_credentials
  m365 = M365.new
  m365.ping?
rescue RuntimeError => e
  say "MS Graph API connectivity failed.", :red
  say "Please check your credentials and configuration.", :red
  say e.message, :red
  exit
end

#check_for_site_and_driveObject

Validate that the configured sharepoint site and drive are accessible



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/m365_active_storage/check/check_generator.rb', line 25

def check_for_site_and_drive
  m365 = M365.new
  site_id, drive_id = m365.config_site_and_drive_id
  site = m365.find_site_by_id(site_id)
  drive = m365.find_sharepoint_drive_by_id(site_id, drive_id) if site
  unless site && drive
    say "Cannot connect to SharePoint site and document library.", :red
    say "Check your site and drive configuration.", :red
    exit
  end
  say "Site: #{site["displayName"]}, drive: #{drive["name"]}", :green
end

#check_service_set_to_sharepointObject

Check if the storage service is set to SharePoint. Just notify if not.



39
40
41
42
43
44
45
# File 'lib/generators/m365_active_storage/check/check_generator.rb', line 39

def check_service_set_to_sharepoint
  current_service = Rails.application.config.active_storage.service
  return if current_service == :sharepoint

  say "config.active_storage.service is set to #{current_service}", :yellow
  exit
end

#final_messageObject

Final message if all checks pass



48
49
50
# File 'lib/generators/m365_active_storage/check/check_generator.rb', line 48

def final_message
  say "M365 Active Storage installation completed successfully!", :green
end