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.
657 658 659 |
# File 'lib/hiiro/tasks.rb', line 657 def apps_file @apps_file end |
#tasks_file ⇒ Object (readonly)
Returns the value of attribute tasks_file.
657 658 659 |
# File 'lib/hiiro/tasks.rb', line 657 def tasks_file @tasks_file end |
Instance Method Details
#apps ⇒ Object
669 670 671 672 673 674 675 676 |
# File 'lib/hiiro/tasks.rb', line 669 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
695 696 697 698 699 700 |
# File 'lib/hiiro/tasks.rb', line 695 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
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/hiiro/tasks.rb', line 678 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 |