Class: SchwarmCli::Commands::Recurring

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/recurring.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/schwarm_cli/commands/recurring.rb', line 34

def create
  handle_errors do
    attrs = {
      name: options[:name], github_repository_id: options[:repo],
      prompt: options[:prompt], schedule: options[:schedule]
    }

    data = client.recurring.create(**attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Schedule" => "schedule" })
  end
end

#delete(id) ⇒ Object



58
59
60
61
62
63
# File 'lib/schwarm_cli/commands/recurring.rb', line 58

def delete(id)
  handle_errors do
    client.recurring.destroy(id)
    puts "Recurring task #{id} deleted."
  end
end

#listObject



9
10
11
12
13
14
15
# File 'lib/schwarm_cli/commands/recurring.rb', line 9

def list
  handle_errors do
    data = client.recurring.list(repository_id: options[:repo], query: options[:query])
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_id],
                                %w[ENABLED enabled], %w[SCHEDULE schedule]])
  end
end

#show(id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/schwarm_cli/commands/recurring.rb', line 18

def show(id)
  handle_errors do
    data = client.recurring.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Name" => "name", "Repository" => "github_repository_id",
                    "Enabled" => "enabled", "Schedule" => "schedule", "Prompt" => "prompt",
                    "Created" => "created_at", "Updated" => "updated_at"
                  })
  end
end

#toggle(id) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/schwarm_cli/commands/recurring.rb', line 66

def toggle(id)
  handle_errors do
    data = client.recurring.toggle(id)
    status = data.dig("data", "enabled") ? "enabled" : "disabled"
    puts "Recurring task #{id} #{status}."
  end
end

#update(id) ⇒ Object



50
51
52
53
54
55
# File 'lib/schwarm_cli/commands/recurring.rb', line 50

def update(id)
  handle_errors do
    data = client.recurring.update(id, **update_attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Schedule" => "schedule" })
  end
end