Class: Invar::Rake::Task::ConfigFileHandler
- Inherits:
-
NamespacedFileTask
- Object
- NamespacedFileTask
- Invar::Rake::Task::ConfigFileHandler
- Defined in:
- lib/invar/rake/task/config.rb
Overview
Rake task handler for actions to do with configuration files
Instance Method Summary collapse
-
#create ⇒ Object
Creates a config file in the appropriate location.
-
#edit ⇒ Object
Edits the existing config file in the appropriate location.
Methods inherited from NamespacedFileTask
Constructor Details
This class inherits a constructor from Invar::Rake::Task::NamespacedFileTask
Instance Method Details
#create ⇒ Object
Creates a config file in the appropriate location
11 12 13 14 15 16 17 |
# File 'lib/invar/rake/task/config.rb', line 11 def create config_dir.mkpath file_path.write CONFIG_TEMPLATE file_path.chmod 0o600 warn "Created file: #{ file_path }" end |
#edit ⇒ Object
Edits the existing config file in the appropriate location
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/invar/rake/task/config.rb', line 20 def edit content = $stdin.stat.pipe? ? $stdin.read : nil file_path = configs_file if content file_path.write content else system ENV.fetch('EDITOR', 'editor'), file_path.to_s, exception: true end warn "File saved to: #{ file_path }" end |