Class: Checkoff::TaskSelectors
- Inherits:
-
Object
- Object
- Checkoff::TaskSelectors
- Defined in:
- lib/checkoff/task_selectors.rb
Overview
Filter lists of tasks using declarative selectors.
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- DAY =
24 * HOUR
- REALLY_LONG_CACHE_TIME =
HOUR * 1
- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE
Class Method Summary collapse
-
.project_name ⇒ String
@sg-ignore.
- .run ⇒ void
- .task_selector ⇒ Array
-
.workspace_name ⇒ String
@sg-ignore.
Instance Method Summary collapse
- #filter_via_task_selector(task, task_selector) ⇒ Boolean
-
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config:).client, tasks: Checkoff::Tasks.new(config:, client:), timelines: Checkoff::Timelines.new(config:, client:), custom_fields: Checkoff::CustomFields.new(config:, client:)) ⇒ TaskSelectors
constructor
@sg-ignore.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config:).client, tasks: Checkoff::Tasks.new(config:, client:), timelines: Checkoff::Timelines.new(config:, client:), custom_fields: Checkoff::CustomFields.new(config:, client:)) ⇒ TaskSelectors
@sg-ignore
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/checkoff/task_selectors.rb', line 28 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config:).client, tasks: Checkoff::Tasks.new(config:, client:), timelines: Checkoff::Timelines.new(config:, client:), custom_fields: Checkoff::CustomFields.new(config:, client:)) @config = config @tasks = tasks @timelines = timelines @custom_fields = custom_fields end |
Class Method Details
.project_name ⇒ String
@sg-ignore
68 69 70 |
# File 'lib/checkoff/task_selectors.rb', line 68 def project_name ARGV[1] || raise('Please pass project name to pull tasks from as first argument') end |
.run ⇒ void
This method returns an undefined value.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/checkoff/task_selectors.rb', line 85 def run require 'checkoff/projects' task_selectors = Checkoff::TaskSelectors.new extra_fields = ['custom_fields'] projects = Checkoff::Projects.new project = projects.project_or_raise(workspace_name, project_name) raw_tasks = projects.tasks_from_project(project, extra_fields:) tasks = raw_tasks.filter { |task| task_selectors.filter_via_task_selector(task, task_selector) } # avoid n+1 queries generating the full task formatting puts JSON.pretty_generate(tasks.map(&:to_h)) end |
.task_selector ⇒ Array
79 80 81 82 |
# File 'lib/checkoff/task_selectors.rb', line 79 def task_selector task_selector_json = ARGV[2] || raise('Please pass task_selector in JSON form as third argument') JSON.parse(task_selector_json) end |
.workspace_name ⇒ String
@sg-ignore
74 75 76 |
# File 'lib/checkoff/task_selectors.rb', line 74 def workspace_name ARGV[0] || raise('Please pass workspace name as first argument') end |
Instance Method Details
#filter_via_task_selector(task, task_selector) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/checkoff/task_selectors.rb', line 46 def filter_via_task_selector(task, task_selector) evaluator = TaskSelectorEvaluator.new(task:, tasks:, timelines:, custom_fields:) evaluator.evaluate(task_selector) end |