Class: Kerbi::Cli::StateHandler

Inherits:
BaseHandler show all
Defined in:
lib/cli/state_handler.rb

Instance Method Summary collapse

Instance Method Details

#delete(release_name, tag_expr) ⇒ Object

Parameters:

  • tag_expr (String)

    e.g 1.9.1, @latest



69
70
71
72
73
74
75
# File 'lib/cli/state_handler.rb', line 69

def delete(release_name, tag_expr)
  mem_dna(release_name)
  entry = find_readable_entry(tag_expr)
  state_backend.delete_entry(entry)
  new_count = state_backend.entries.count
  puts "Deleted state[#{entry.tag}]. Remaining entries: #{new_count}"
end

#demote(release_name, tag_expr) ⇒ Object

Parameters:

  • tag_expr (String)

    e.g 1.9.1, @latest



49
50
51
52
53
54
# File 'lib/cli/state_handler.rb', line 49

def demote(release_name, tag_expr)
  mem_dna(release_name)
  entry = find_readable_entry(tag_expr)
  old_name = entry.demote
  touch_and_save_entry(entry, tag: old_name)
end

#list(release_name) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/cli/state_handler.rb', line 5

def list(release_name)
  prep_opts(Kerbi::Consts::OptionDefaults::LIST_STATE)
  mem_dna(release_name)
  echo_data(
    state_backend.entries,
    table_serializer: Kerbi::Cli::EntryRowSerializer,
    serializer: Kerbi::Cli::EntryYamlJsonSerializer
  )
end

#promote(release_name, tag_expr) ⇒ Object

Parameters:

  • tag_expr (String)

    e.g 1.9.1, @latest



40
41
42
43
44
45
# File 'lib/cli/state_handler.rb', line 40

def promote(release_name, tag_expr)
  mem_dna(release_name)
  entry = find_readable_entry(tag_expr)
  old_name = entry.promote
  touch_and_save_entry(entry, tag: old_name)
end

#prune_candidates(release_name) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/cli/state_handler.rb', line 78

def prune_candidates(release_name)
  mem_dna(release_name)
  old_count = entry_set.entries.count
  entry_set.prune_candidates
  state_backend.save
  new_count = entry_set.entries.count
  puts "Pruned #{old_count - new_count} state entries"
end

#retag(release_name, old_tag_expr, new_tag_expr) ⇒ Object

Parameters:

  • old_tag_expr (String)

    e.g 1.9.1, @latest

  • new_tag_expr (String)

    e.g 1.9.1, @latest



31
32
33
34
35
36
# File 'lib/cli/state_handler.rb', line 31

def retag(release_name, old_tag_expr, new_tag_expr)
  mem_dna(release_name)
  entry = find_readable_entry(old_tag_expr)
  old_tag = entry.retag(new_tag_expr)
  touch_and_save_entry(entry, tag: old_tag)
end

#set(release_name, tag_expr, attr_name, new_value) ⇒ Object

Parameters:

  • tag_expr (String)

    e.g 1.9.1, @latest

  • attr_name (String)

    e.g message

  • new_value (String)

    e.g i am a new message



60
61
62
63
64
65
# File 'lib/cli/state_handler.rb', line 60

def set(release_name, tag_expr, attr_name, new_value)
  mem_dna(release_name)
  entry = find_readable_entry(tag_expr)
  old_value = entry.assign_attr(attr_name, new_value)
  touch_and_save_entry(entry, attr_name => old_value)
end

#show(release_name, tag_expr) ⇒ Object

Parameters:

  • tag_expr (String)

    e.g 1.9.1, @latest



17
18
19
20
21
22
23
24
25
26
# File 'lib/cli/state_handler.rb', line 17

def show(release_name, tag_expr)
  prep_opts(Kerbi::Consts::OptionDefaults::LIST_STATE)
  mem_dna(release_name)
  entry = find_readable_entry(tag_expr)
  echo_data(
    entry,
    table_serializer: Kerbi::Cli::FullEntryRowSerializer,
    serializer: Kerbi::Cli::EntryYamlJsonSerializer
  )
end