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 = <<~YAML # Watchcat Configuration File watches: - path: "./src" recursive: true debounce: 300 filters: ignore_access: true patterns: - "*.js" - "*.ts" - "*.css" actions: - command: "echo 'File changed: {{file_path}}'" - path: "./docs" recursive: true filters: ignore_access: true patterns: - "*.md" actions: - command: "echo 'Documentation updated: {{file_name}}'" YAML if File.exist?(file_path) raise Error, "File already exists: #{file_path}. Won't overwrite." end File.write(file_path, template) puts "Config template generated at #{file_path}" end |
.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.}" end end |