Class: Checkoff::Resources

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

Overview

Deal with Asana resources across different resource types

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) ⇒ Resources

Returns a new instance of Resources.

Parameters:



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

Class Method Details

.runvoid

This method returns an undefined value.



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

def run
  # # @sg-ignore
  # # @type [String]
  # workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  # # @sg-ignore
  # # @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

#resource_by_gid(gid, resource_type: nil) ⇒ Array([Asana::Resource, nil], [String,nil])

Attempt to look up a GID, even in situations where we don’t have a resource type provided.

Parameters:

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

Returns:

  • (Array([Asana::Resource, nil], [String,nil]))


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