Class: Appydave::Tools::Configuration::ExampleInstaller
- Inherits:
-
Object
- Object
- Appydave::Tools::Configuration::ExampleInstaller
- Defined in:
- lib/appydave/tools/configuration/example_installer.rb
Overview
Installs bundled example configuration files into the user’s config directory.
Example files live at config/examples/*.example.json inside the gem. Each file is installed without the ‘.example` segment in its name so that `settings.example.json` becomes `settings.json` in the target directory.
Files are never overwritten — existing files are skipped and reported.
Constant Summary collapse
- EXAMPLES_PATH =
File.('../../../../config/examples', __dir__)
Instance Method Summary collapse
-
#available ⇒ Array<String>
List the filenames that would be installed (target names, not source names).
-
#initialize(target_path: nil) ⇒ ExampleInstaller
constructor
A new instance of ExampleInstaller.
-
#install ⇒ Hash
Install all bundled example files that do not yet exist.
Constructor Details
#initialize(target_path: nil) ⇒ ExampleInstaller
Returns a new instance of ExampleInstaller.
23 24 25 |
# File 'lib/appydave/tools/configuration/example_installer.rb', line 23 def initialize(target_path: nil) @target_path = target_path || Config.config_path end |
Instance Method Details
#available ⇒ Array<String>
List the filenames that would be installed (target names, not source names).
52 53 54 |
# File 'lib/appydave/tools/configuration/example_installer.rb', line 52 def available example_files.map { |f| target_name(f) } end |
#install ⇒ Hash
Install all bundled example files that do not yet exist.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/appydave/tools/configuration/example_installer.rb', line 30 def install FileUtils.mkdir_p(@target_path) results = { installed: [], skipped: [] } example_files.each do |src| dest = destination_for(src) basename = File.basename(dest) if File.exist?(dest) results[:skipped] << basename else FileUtils.cp(src, dest) results[:installed] << basename end end results end |