class Abt::Providers::Harvest::BaseCommand
Attributes
config[R]
path[R]
Public Class Methods
new(ari:, cli:)
click to toggle source
Calls superclass method
Abt::BaseCommand::new
# File lib/abt/providers/harvest/base_command.rb, line 13 def initialize(ari:, cli:) super @config = Configuration.new(cli: cli) @path = ari.path ? Path.new(ari.path) : config.path end
Private Instance Methods
api()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 96 def api @api ||= Abt::Providers::Harvest::Api.new(access_token: config.access_token, account_id: config.account_id) end
print_project(project)
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 80 def print_project(project) cli.print_ari( "harvest", project["id"], "#{project['client']['name']} > #{project['name']}" ) end
print_task(project, task)
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 88 def print_task(project, task) cli.print_ari( "harvest", "#{project['id']}/#{task['id']}", "#{project['name']} > #{task['name']}" ) end
project()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 61 def project return @project if instance_variable_defined?(:@project) @project = if project_assignment project_assignment["project"].merge("client" => project_assignment["client"]) end end
project_assignment()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 69 def project_assignment @project_assignment ||= project_assignments.find { |pa| pa["project"]["id"].to_s == path.project_id } end
project_assignments()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 73 def project_assignments @project_assignments ||= begin warn("Fetching Harvest data...") api.get_paged("users/me/project_assignments") end end
prompt_project!()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 39 def prompt_project! result = Services::ProjectPicker.call(cli: cli, project_assignments: project_assignments) @path = result.path @project = result.project end
prompt_task!()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 45 def prompt_task! result = Services::TaskPicker.call(cli: cli, path: path, project_assignment: project_assignment) @path = result.path @task = result.task end
require_local_config!()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 22 def require_local_config! abort("Must be run inside a git repository") unless config.local_available? end
require_project!()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 26 def require_project! return if project_id abort("No current/specified project. Did you forget to run `pick`?") end
require_task!()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 32 def require_task! require_project! return if task_id abort("No current/specified task. Did you forget to run `pick`?") end
task()
click to toggle source
# File lib/abt/providers/harvest/base_command.rb, line 51 def task return @task if instance_variable_defined?(:@task) @task = if project_assignment project_assignment["task_assignments"].map { |ta| ta["task"] }.find do |task| task["id"].to_s == task_id end end end