Class: Graphina::Setup
- Inherits:
-
Object
- Object
- Graphina::Setup
- Includes:
- FileUtils::Verbose
- Defined in:
- lib/graphina/setup.rb
Overview
A class that handles the setup and configuration of Graphina
The Setup class provides functionality for installing default panel configurations into the user’s configuration directory. It manages the detection of platform-specific default configurations and facilitates the copying of these configurations to the appropriate location for use with the Graphina application
Instance Method Summary collapse
-
#default_panels_path(panels_name) ⇒ Pathname?
The default_panels_path method constructs and returns a Pathname object for a default panels configuration file.
-
#infer_default_panels_path_from_platform ⇒ Pathname?
The infer_default_panels_path_from_platform method attempts to determine the appropriate default panel configuration file path based on the current platform.
-
#initialize(default_panels_name:) ⇒ Graphina::Setup
constructor
The initialize method sets up a Setup instance with the specified default panel name.
-
#install_default_panels ⇒ Object
The install_default_panels method installs default panel configurations into the user’s configuration directory.
-
#panels_path_exist? ⇒ Boolean
The panels_path_exist? method checks whether the panel configuration file path exists in the user’s configuration directory.
Constructor Details
#initialize(default_panels_name:) ⇒ Graphina::Setup
The initialize method sets up a Setup instance with the specified default panel name
This method configures a new setup object with a default panel name, handling the special case where the name is ‘default’ by setting it to nil instead
27 28 29 30 |
# File 'lib/graphina/setup.rb', line 27 def initialize(default_panels_name:) default_panels_name == 'default' and default_panels_name = nil @default_panels_name = default_panels_name end |
Instance Method Details
#default_panels_path(panels_name) ⇒ Pathname?
The default_panels_path method constructs and returns a Pathname object for a default panels configuration file
This method takes a panel name parameter and uses it to build a file path pointing to a default panels configuration file located in the panel defaults directory. It checks if the constructed path exists and returns it if so, or nil if the file doesn’t exist
69 70 71 72 73 74 |
# File 'lib/graphina/setup.rb', line 69 def default_panels_path(panels_name) path = Pathname.new(__FILE__).dirname + 'panel' + 'defaults' + (panels_name + '.yml') if path.exist? path end end |
#infer_default_panels_path_from_platform ⇒ Pathname?
The infer_default_panels_path_from_platform method attempts to determine the appropriate default panel configuration file path based on the current platform
This method checks the RUBY_PLATFORM environment variable to identify whether the system is running on an x86_64 Darwin (macOS) or x86_64 Linux platform
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/graphina/setup.rb', line 44 def infer_default_panels_path_from_platform case RUBY_PLATFORM when /\A(x86_64|arm64)-darwin/, /\Ax86_64-linux/ path = default_panels_path($&) if path.exist? path end else STDERR.puts "Default panel configuration cannot be inferred for platform!" nil end end |
#install_default_panels ⇒ Object
The install_default_panels method installs default panel configurations into the user’s configuration directory
This method checks if a panel configuration file already exists in the user’s configuration directory and, if not, attempts to determine the appropriate default panel configuration based on the platform or the specified default panel name, then copies the default configuration file to the user’s configuration directory
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/graphina/setup.rb', line 96 def install_default_panels if panels_path_exist? STDOUT.print "#{Graphina::GraphinaConfig::PANELS_PATH.to_s.inspect} exists. Overwrite (y/n)? " STDIN.gets !~ /\Ay/i and return end default_path = @default_panels_name ? default_panels_path(@default_panels_name) : infer_default_panels_path_from_platform if default_path mkdir_p Graphina::GraphinaConfig::CONFIG_DIR cp default_path, Graphina::GraphinaConfig::PANELS_PATH STDOUT.puts "Default panels from #{default_path.to_s.inspect} have been installed." else STDERR.puts "Default panels for #{@default_panels_name.inspect} could not be installed." end end |
#panels_path_exist? ⇒ Boolean
The panels_path_exist? method checks whether the panel configuration file path exists in the user’s configuration directory
This method verifies the existence of the panels configuration file by querying the predefined path in the Graphina configuration module
84 85 86 |
# File 'lib/graphina/setup.rb', line 84 def panels_path_exist? Graphina::GraphinaConfig::PANELS_PATH.exist? end |