Class: Checkoff::TaskSelectors

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, tasks: Checkoff::Tasks.new(config: config, client: client), timelines: Checkoff::Timelines.new(config: config, client: client), custom_fields: Checkoff::CustomFields.new(config: config, client: client)) ⇒ TaskSelectors

@sg-ignore

Parameters:

  • config (Hash) (defaults to: Checkoff::Internal::ConfigLoader.load(:asana))
  • client (Asana::Client) (defaults to: Checkoff::Clients.new(config: config).client)
  • tasks (Checkoff::Tasks) (defaults to: Checkoff::Tasks.new(config: config, client: client))
  • timelines (Checkoff::Timelines) (defaults to: Checkoff::Timelines.new(config: config, client: client))


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/checkoff/task_selectors.rb', line 27

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               client: Checkoff::Clients.new(config: config).client,
               tasks: Checkoff::Tasks.new(config: config,
                                          client: client),
               timelines: Checkoff::Timelines.new(config: config,
                                                  client: client),
               custom_fields: Checkoff::CustomFields.new(config: config,
                                                         client: client))
  @config = config
  @tasks = tasks
  @timelines = timelines
  @custom_fields = custom_fields
end

Class Method Details

.project_nameString

@sg-ignore

Returns:

  • (String)


67
68
69
# File 'lib/checkoff/task_selectors.rb', line 67

def project_name
  ARGV[1] || raise('Please pass project name to pull tasks from as first argument')
end

.runvoid

This method returns an undefined value.



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/checkoff/task_selectors.rb', line 84

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: 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_selectorArray

Returns:

  • (Array)


78
79
80
81
# File 'lib/checkoff/task_selectors.rb', line 78

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_nameString

@sg-ignore

Returns:

  • (String)


73
74
75
# File 'lib/checkoff/task_selectors.rb', line 73

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

Parameters:

  • task (Asana::Resources::Task)
  • task_selector (Array<(Symbol, Array)>)

    Filter based on task details. Examples: [:tag, ‘foo’] [:not, [:tag, ‘foo’]] [:tag, ‘foo’]

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/checkoff/task_selectors.rb', line 45

def filter_via_task_selector(task, task_selector)
  evaluator = TaskSelectorEvaluator.new(task: task, tasks: tasks, timelines: timelines,
                                        custom_fields: custom_fields)
  evaluator.evaluate(task_selector)
end