Class: Patcmd::CLI::ConfigurationManager
- Inherits:
-
Object
- Object
- Patcmd::CLI::ConfigurationManager
- Defined in:
- lib/patcmd/cli/configuration_manager.rb
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
Instance Method Summary collapse
- #add_task(task) ⇒ Object
- #all_tasks ⇒ Object
- #find_task(category, name, action) ⇒ Object
- #init_config ⇒ Object
-
#initialize(config_path) ⇒ ConfigurationManager
constructor
A new instance of ConfigurationManager.
Constructor Details
#initialize(config_path) ⇒ ConfigurationManager
Returns a new instance of ConfigurationManager.
11 12 13 14 15 |
# File 'lib/patcmd/cli/configuration_manager.rb', line 11 def initialize(config_path) @config_path = config_path ensure_config_file @config = load_config end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
9 10 11 |
# File 'lib/patcmd/cli/configuration_manager.rb', line 9 def config_path @config_path end |
Instance Method Details
#add_task(task) ⇒ Object
36 37 38 39 |
# File 'lib/patcmd/cli/configuration_manager.rb', line 36 def add_task(task) @config["tasks"] << task save_config end |
#all_tasks ⇒ Object
47 48 49 |
# File 'lib/patcmd/cli/configuration_manager.rb', line 47 def all_tasks @config["tasks"] end |
#find_task(category, name, action) ⇒ Object
41 42 43 44 45 |
# File 'lib/patcmd/cli/configuration_manager.rb', line 41 def find_task(category, name, action) @config["tasks"].find do |task| task["category"] == category && task["name"] == name && task["action"] == action end end |
#init_config ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/patcmd/cli/configuration_manager.rb', line 17 def init_config unless File.exist?(@config_path) default_task = { "category" => "Default", "name" => "HelloWorld", "description" => "A simple Hello World task", "path" => "/usr/local/bin", "action" => "execute", "command" => "echo", "args" => ["Hello, World!"], "environments" => { "ENV" => "development" }, } default_config = { "tasks" => [default_task] } FileUtils.mkdir_p(File.dirname(@config_path)) File.write(@config_path, default_config.to_yaml) end end |