Module: Env
- Defined in:
- lib/autosparkle/environment/environment.rb
Overview
Environment module to load the environment variables It contains the app state
Class Attribute Summary collapse
-
.storage ⇒ Object
Returns the value of attribute storage.
-
.variables ⇒ Object
Returns the value of attribute variables.
-
.verbose_enabled ⇒ Object
Returns the value of attribute verbose_enabled.
Class Method Summary collapse
- .initialize(options, command) ⇒ Object
- .initialize_automate(options) ⇒ Object
- .initialize_distribute(options) ⇒ Object
- .initialize_export(options) ⇒ Object
- .initialize_package(options) ⇒ Object
- .load_environment(project_directory_path, env) ⇒ Object
- .retreive_versions_variables_form_appcast(options) ⇒ Object
- .retrieve_storage ⇒ Object
- .retrieve_variables_from_xcode(project_path, workspace_path) ⇒ Object
Class Attribute Details
.storage ⇒ Object
Returns the value of attribute storage.
25 26 27 |
# File 'lib/autosparkle/environment/environment.rb', line 25 def storage @storage end |
.variables ⇒ Object
Returns the value of attribute variables.
25 26 27 |
# File 'lib/autosparkle/environment/environment.rb', line 25 def variables @variables end |
.verbose_enabled ⇒ Object
Returns the value of attribute verbose_enabled.
25 26 27 |
# File 'lib/autosparkle/environment/environment.rb', line 25 def verbose_enabled @verbose_enabled end |
Class Method Details
.initialize(options, command) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/autosparkle/environment/environment.rb', line 27 def initialize(, command) project_path = .project_path workspace_path = .workspace_path project_directory_path = File.dirname(workspace_path || project_path) if workspace_path || project_path ENV['PROJECT_DIRECTORY_PATH'] = project_directory_path load_environment(project_directory_path, .env) @variables = DefaultEnvironmentVariables.new case command when Command::EXPORT initialize_export() when Command::PACKAGE initialize_package() when Command::DISTRIBUTE initialize_distribute() when Command::AUTOMATE initialize_automate() end puts_if_verbose "Running the script with the #{.env} environment...\n" end |
.initialize_automate(options) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/autosparkle/environment/environment.rb', line 69 def self.initialize_automate() retrieve_variables_from_xcode(.project_path, .workspace_path) @storage = retrieve_storage retreive_versions_variables_form_appcast() end |
.initialize_distribute(options) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/autosparkle/environment/environment.rb', line 61 def self.initialize_distribute() ENV['APP_DISPLAY_NAME'] = .app_display_name ENV['MINIMUM_MACOS_VERSION'] = .minimum_macos_version @storage = retrieve_storage retreive_versions_variables_form_appcast() end |
.initialize_export(options) ⇒ Object
53 54 55 |
# File 'lib/autosparkle/environment/environment.rb', line 53 def self.initialize_export() retrieve_variables_from_xcode(.project_path, .workspace_path) end |
.initialize_package(options) ⇒ Object
57 58 59 |
# File 'lib/autosparkle/environment/environment.rb', line 57 def self.initialize_package() ENV['APP_DISPLAY_NAME'] = .app_display_name end |
.load_environment(project_directory_path, env) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/autosparkle/environment/environment.rb', line 76 def self.load_environment(project_directory_path, env) env_is_file = File.file?(env) if !project_directory_path && !env_is_file raise 'Cannot find the project directory path to load the environment variables' end env_file_path = if env_is_file env else File.join(project_directory_path, ".env.autosparkle.#{env}") end ENV['ENV_FILE_PATH'] = env_file_path puts_if_verbose "Loading the environment variables from #{env_file_path}..." Dotenv.load(env_file_path) end |
.retreive_versions_variables_form_appcast(options) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/autosparkle/environment/environment.rb', line 113 def self.retreive_versions_variables_form_appcast() marketing_version, current_project_version = AppcastXML.retreive_versions(@storage.deployed_appcast_xml) ENV['MARKETING_VERSION'] = .marketing_version || marketing_version ENV['CURRENT_PROJECT_VERSION'] = .current_project_version || current_project_version end |
.retrieve_storage ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/autosparkle/environment/environment.rb', line 93 def self.retrieve_storage storage_type = ENV.fetch('STORAGE_TYPE', nil) raise 'Storage type is not defined in the environment' if storage_type.nil? || storage_type.empty? case storage_type when 'aws-s3' AwsS3Storage.new else raise "Storage type #{storage_type} is not supported" end end |
.retrieve_variables_from_xcode(project_path, workspace_path) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/autosparkle/environment/environment.rb', line 105 def self.retrieve_variables_from_xcode(project_path, workspace_path) puts_if_verbose 'Fetching the minimum macOS version from the Xcode project...' ENV['MINIMUM_MACOS_VERSION'] = Xcodeproj.get_minimum_deployment_macos_version(project_path, workspace_path) puts_if_verbose 'Fetching the app display name from the Xcode project...' ENV['APP_DISPLAY_NAME'] = Xcodeproj.get_app_display_name(project_path, workspace_path) end |