Class: Checkoff::Resources

Inherits:
Object
  • Object
show all
Extended by:
CacheMethod::ClassMethods
Defined in:
lib/checkoff/resources.rb,
sig/checkoff.rbs

Overview

Deal with Asana resources across different resource types

Constant Summary collapse

MINUTE =

Returns:

  • (Object)
60
HOUR =

Returns:

  • (Object)
MINUTE * 60
DAY =

Returns:

  • (Object)
24 * HOUR
REALLY_LONG_CACHE_TIME =

Returns:

  • (Object)
HOUR * 1
LONG_CACHE_TIME =

Returns:

  • (Object)
MINUTE * 15
SHORT_CACHE_TIME =

Returns:

  • (Object)
MINUTE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), tasks: Checkoff::Tasks.new(config:), sections: Checkoff::Sections.new(config:), projects: Checkoff::Projects.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) ⇒ Object

sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param config

@param workspaces

@param tasks

@param sections

@param projects

@param clients

@param client



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/checkoff/resources.rb', line 40

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               workspaces: Checkoff::Workspaces.new(config:),
               tasks: Checkoff::Tasks.new(config:),
               sections: Checkoff::Sections.new(config:),
               projects: Checkoff::Projects.new(config:),
               clients: Checkoff::Clients.new(config:),
               client: clients.client)
  @workspaces = workspaces
  @tasks = tasks
  @sections = sections
  @projects = projects
  @client = client
end

Instance Attribute Details

#clientAsana::Client (readonly)

sord warn - Asana::Client wasn't able to be resolved to a constant in this project

Returns:

  • (Asana::Client)


109
110
111
# File 'lib/checkoff/resources.rb', line 109

def client
  @client
end

#projectsCheckoff::Projects (readonly)

Returns:



100
101
102
# File 'lib/checkoff/resources.rb', line 100

def projects
  @projects
end

#sectionsCheckoff::Sections (readonly)

Returns:



103
104
105
# File 'lib/checkoff/resources.rb', line 103

def sections
  @sections
end

#tasksCheckoff::Tasks (readonly)

Returns:



106
107
108
# File 'lib/checkoff/resources.rb', line 106

def tasks
  @tasks
end

#workspacesCheckoff::Workspaces (readonly)



97
98
99
# File 'lib/checkoff/resources.rb', line 97

def workspaces
  @workspaces
end

Class Method Details

.runvoid

This method returns an undefined value.



115
116
117
118
119
120
121
122
123
# File 'lib/checkoff/resources.rb', line 115

def run
  # # @type [String]
  # workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  # # @type [String]
  # resource_name = ARGV[1] || raise('Please pass resource name as second argument')
  # resources = Checkoff::Resources.new
  # resource = resources.resource_or_raise(workspace_name, resource_name)
  # puts "Results: #{resource}"
end

Instance Method Details

#fetch_project_gid(project_gid) ⇒ Asana::Resources::Project?

sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param project_gid

Parameters:

  • project_gid (String)

Returns:

  • (Asana::Resources::Project, nil)


92
93
94
# File 'lib/checkoff/resources.rb', line 92

def fetch_project_gid(project_gid)
  projects.project_by_gid(project_gid)
end

#fetch_section_gid(section_gid) ⇒ Asana::Resources::Section?

sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param section_gid

Parameters:

  • section_gid (String)

Returns:

  • (Asana::Resources::Section, nil)


85
86
87
# File 'lib/checkoff/resources.rb', line 85

def fetch_section_gid(section_gid)
  sections.section_by_gid(section_gid)
end

#fetch_task_gid(gid) ⇒ Asana::Resources::Task?

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param gid

Parameters:

  • gid (String)

Returns:

  • (Asana::Resources::Task, nil)


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

def fetch_task_gid(gid)
  tasks.task_by_gid(gid, only_uncompleted: false)
end

#resource_by_gid(gid, resource_type: nil) ⇒ [untyped, untyped, untyped, untyped]

sord warn - "[Asana::Resource" does not appear to be a type sord warn - "nil]" does not appear to be a type sord warn - "[String" does not appear to be a type sord warn - "nil]" does not appear to be a type Attempt to look up a GID, even in situations where we don't have a resource type provided.

@param gid

@param resource_type

Parameters:

  • gid (String)
  • resource_type: (String, nil) (defaults to: nil)

Returns:

  • ([untyped, untyped, untyped, untyped])


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/checkoff/resources.rb', line 61

def resource_by_gid(gid, resource_type: nil)
  %w[task section project].each do |resource_type_to_try|
    next unless [resource_type_to_try, nil].include?(resource_type)

    # @type [Asana::Resources::Resource, nil]
    resource = T.cast(method(:"fetch_#{resource_type_to_try}_gid").call(gid),
                      T.nilable(Asana::Resources::Resource))
    return [resource, resource_type_to_try] if resource
  end
  [nil, nil]
end