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(Symbol, Array)
@sg-ignore.
-
.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
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/checkoff/task_selectors.rb', line 29 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
69 70 71 |
# File 'lib/checkoff/task_selectors.rb', line 69 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.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/checkoff/task_selectors.rb', line 89 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(Symbol, Array)
@sg-ignore
81 82 83 84 85 86 |
# File 'lib/checkoff/task_selectors.rb', line 81 def task_selector task_selector_json = ARGV[2] || raise('Please pass task_selector in JSON form as third argument') # @return [Symbol, Array] T.cast(JSON.parse(task_selector_json), [Symbol, Array]) end |
.workspace_name ⇒ String
@sg-ignore
75 76 77 |
# File 'lib/checkoff/task_selectors.rb', line 75 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
47 48 49 50 51 |
# File 'lib/checkoff/task_selectors.rb', line 47 def filter_via_task_selector(task, task_selector) evaluator = TaskSelectorEvaluator.new(task:, tasks:, timelines:, custom_fields:) !!evaluator.evaluate(task_selector) end |