Class: Psdk::Cli::Configuration
- Inherits:
-
Object
- Object
- Psdk::Cli::Configuration
- Defined in:
- lib/psdk/cli/configuration.rb
Overview
Class holding the configuration of the Cli
Constant Summary collapse
- PROJECT_CONFIGURATION_FILENAME =
Filename of the project configuration
'.psdk-cli.yml'- PATH =
Path where all the global configuration are stored
File.join(ENV.fetch('PSDK_CLI_DIR', Dir.home || ENV['USERPROFILE'] || '~'), '.psdk-cli')
- GLOBAL_CONFIGURATION_FILENAME =
Filename of the global configuration
File.join(PATH, 'config.yml')
Class Attribute Summary collapse
-
.project_path ⇒ String | nil
readonly
Get the project path.
Instance Attribute Summary collapse
-
#project_paths ⇒ Array<String>
Get the project paths.
-
#studio_path ⇒ String
Get the Pokémon Studio path.
Class Method Summary collapse
-
.get(type) ⇒ Configuration
Get the configuration.
-
.save ⇒ Object
Save the configuration.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Configuration
constructor
Create a new configuration.
- #to_h ⇒ Object
Constructor Details
#initialize(hash) ⇒ Configuration
Create a new configuration
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/psdk/cli/configuration.rb', line 20 def initialize(hash) hash = {} unless hash.is_a?(Hash) # @type [String] @studio_path = '' # @type [Array<String>] @project_paths = [] self.studio_path = hash[:studio_path] if hash.key?(:studio_path) self.project_paths = hash[:project_paths] if hash.key?(:project_paths) end |
Class Attribute Details
.project_path ⇒ String | nil (readonly)
Get the project path
78 79 80 |
# File 'lib/psdk/cli/configuration.rb', line 78 def project_path @project_path end |
Instance Attribute Details
#project_paths ⇒ Array<String>
Get the project paths
48 49 50 |
# File 'lib/psdk/cli/configuration.rb', line 48 def project_paths @project_paths end |
#studio_path ⇒ String
Get the Pokémon Studio path
33 34 35 |
# File 'lib/psdk/cli/configuration.rb', line 33 def studio_path @studio_path end |
Class Method Details
.get(type) ⇒ Configuration
Get the configuration
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/psdk/cli/configuration.rb', line 83 def get(type) @global ||= Configuration.new(load_hash(GLOBAL_CONFIGURATION_FILENAME)) return @global if type == :global project_path = find_project_path @local = nil if @project_path != project_path @project_path = project_path @local ||= Configuration.new( @global.to_h.merge(load_hash(File.join(*@project_path, PROJECT_CONFIGURATION_FILENAME))) ) return @local end |
.save ⇒ Object
Save the configuration
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/psdk/cli/configuration.rb', line 98 def save make_config_global_dir File.write(GLOBAL_CONFIGURATION_FILENAME, YAML.dump(@global.to_h)) return unless @local && @project_path local_configuration = @local.to_h # Delete global configuration keys local_configuration.delete(:project_paths) File.write(File.join(@project_path, PROJECT_CONFIGURATION_FILENAME), YAML.dump(local_configuration)) end |
Instance Method Details
#to_h ⇒ Object
65 66 67 68 69 70 |
# File 'lib/psdk/cli/configuration.rb', line 65 def to_h return { studio_path: @studio_path, project_paths: @project_paths } end |