Class: Hiiro::TaskManager::Config
- Inherits:
-
Object
- Object
- Hiiro::TaskManager::Config
- Defined in:
- lib/hiiro/tasks.rb
Instance Attribute Summary collapse
-
#apps_file ⇒ Object
readonly
Returns the value of attribute apps_file.
-
#tasks_file ⇒ Object
readonly
Returns the value of attribute tasks_file.
Instance Method Summary collapse
- #apps ⇒ Object
-
#initialize(tasks_file: nil, apps_file: nil) ⇒ Config
constructor
A new instance of Config.
- #remove_task(name) ⇒ Object
- #save_task(task) ⇒ Object
- #tasks ⇒ Object
Constructor Details
Instance Attribute Details
#apps_file ⇒ Object (readonly)
Returns the value of attribute apps_file.
708 709 710 |
# File 'lib/hiiro/tasks.rb', line 708 def apps_file @apps_file end |
#tasks_file ⇒ Object (readonly)
Returns the value of attribute tasks_file.
708 709 710 |
# File 'lib/hiiro/tasks.rb', line 708 def tasks_file @tasks_file end |
Instance Method Details
#apps ⇒ Object
720 721 722 723 724 725 726 727 |
# File 'lib/hiiro/tasks.rb', line 720 def apps rows = AppRecord.all_as_hash return fallback_load_apps_from_yaml if rows.empty? rows.map { |name, path| App.new(name: name, path: path) } rescue => e warn "Failed to load apps from DB: #{e}. Falling back to YAML." fallback_load_apps_from_yaml end |
#remove_task(name) ⇒ Object
746 747 748 749 750 751 |
# File 'lib/hiiro/tasks.rb', line 746 def remove_task(name) TaskRecord.where(name: name).delete save_tasks_yaml_backup rescue => e warn "Failed to remove task from DB: #{e}" end |
#save_task(task) ⇒ Object
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/hiiro/tasks.rb', line 729 def save_task(task) TaskRecord.find_or_create(name: task.name) do |r| r.tree = task.tree_name r.session = task.session_name r.app = task.respond_to?(:app) ? task.app : nil r.color_index = task.color_index end.update( tree: task.tree_name, session: task.session_name, app: task.respond_to?(:app) ? task.app : nil, color_index: task.color_index ) save_tasks_yaml_backup rescue => e warn "Failed to save task to DB: #{e}" end |