Class: RosettAi::Thor::Tasks::Behaviour

Inherits:
Thor
  • Object
show all
Defined in:
lib/rosett_ai/thor/tasks/behaviour.rb

Overview

Behaviour configuration management tasks

Instance Method Summary collapse

Instance Method Details

#displayvoid

This method returns an undefined value.

Display a summary overview of behaviours.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/rosett_ai/thor/tasks/behaviour.rb', line 287

def display
  behaviours = load_all_behaviours

  if behaviours.empty?
    puts Rainbow(t('no_files')).yellow
    return
  end

  sanitized = RosettAi::TextSanitizer.sanitize_for_display(behaviours)
  case options[:format]
  when 'json'
    puts JSON.pretty_generate(sanitized)
  when 'yaml'
    puts sanitized.to_yaml
  else
    display_table(sanitized)
  end
end

#listvoid

This method returns an undefined value.

List available items.



317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/rosett_ai/thor/tasks/behaviour.rb', line 317

def list
  files = behaviour_files
  if files.empty?
    puts Rainbow(t('no_files_short')).yellow
    return
  end

  puts Rainbow(t('files_title')).bright
  files.each do |file|
    puts "  #{Rainbow(File.basename(file, '.yml')).cyan}"
  end
end

#show(name) ⇒ void

This method returns an undefined value.

Display detailed information for the named item.

Parameters:

  • name (Object)

    the name



344
345
346
347
348
349
350
351
352
353
# File 'lib/rosett_ai/thor/tasks/behaviour.rb', line 344

def show(name)
  name = RosettAi::TextSanitizer.normalize_nfc(name)
  file_path = find_behaviour_file(name)
  raise ::Thor::Error, Rainbow(t('not_found', name: name)).red unless file_path

  content = RosettAi::YamlLoader.load_file(file_path)
  puts YAML.dump(RosettAi::TextSanitizer.sanitize_for_display(content))
rescue Psych::SyntaxError => e
  raise ::Thor::Error, Rainbow(t('yaml_syntax_error', path: file_path, detail: e.message)).red
end

#validate(name = nil) ⇒ Object

Raises:

  • (::Thor::Error)


368
369
370
371
372
373
374
375
# File 'lib/rosett_ai/thor/tasks/behaviour.rb', line 368

def validate(name = nil)
  name = RosettAi::TextSanitizer.normalize_nfc(name) if name
  files = files_to_validate(name)
  return puts Rainbow(t('no_validate')).yellow if files.empty?

  all_valid = validate_files(files)
  raise ::Thor::Error, t('validation_failed') unless all_valid
end