Class: Watchcat::CLI::Config
- Inherits:
-
Object
- Object
- Watchcat::CLI::Config
- Defined in:
- lib/watchcat/cli/config.rb
Instance Attribute Summary collapse
-
#watches ⇒ Object
readonly
Returns the value of attribute watches.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(data) ⇒ Config
Returns a new instance of Config.
8 9 10 |
# File 'lib/watchcat/cli/config.rb', line 8 def initialize(data) @watches = parse_watches(data["watches"] || []) end |
Instance Attribute Details
#watches ⇒ Object (readonly)
Returns the value of attribute watches.
6 7 8 |
# File 'lib/watchcat/cli/config.rb', line 6 def watches @watches end |
Class Method Details
.generate_template(file_path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/watchcat/cli/config.rb', line 25 def self.generate_template(file_path) template = " # Watchcat Configuration File\n\n watches:\n - path: \"./src\"\n recursive: true\n debounce: 300\n filters:\n ignore_access: true\n patterns:\n - \"*.js\"\n - \"*.ts\"\n - \"*.css\"\n actions:\n - command: \"echo 'File changed: {{file_path}}'\"\n\n - path: \"./docs\"\n recursive: true\n filters:\n ignore_access: true\n patterns:\n - \"*.md\"\n actions:\n - command: \"echo 'Documentation updated: {{file_name}}'\"\n YAML\n\n if File.exist?(file_path)\n raise Error, \"File already exists: \#{file_path}. Won't overwrite.\"\n end\n\n File.write(file_path, template)\n puts \"Config template generated at \#{file_path}\"\nend\n" |
.load(file_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/watchcat/cli/config.rb', line 12 def self.load(file_path) unless File.exist?(file_path) raise Error, "Configuration file not found: #{file_path}" end begin data = Psych.load_file(file_path) new(data) rescue Psych::SyntaxError => e raise Error, "Invalid YAML syntax in #{file_path}: #{e.message}" end end |