Class: SubCommands::Tags

Inherits:
Thor
  • Object
show all
Defined in:
lib/subcommands/tags.rb

Instance Method Summary collapse

Instance Method Details

#add(tag) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/subcommands/tags.rb', line 4

def add(tag)
    tag = ::Tag.new(tag: tag.strip)

    if !tag.save
        tag.errors.full_messages.each do |error|
            say error, :red
        end
        exit 1
    end

    say tag.tag + " added!", :green
end

#lsObject



27
28
29
30
31
32
33
34
35
# File 'lib/subcommands/tags.rb', line 27

def ls
    tags = ::Tag.order(options[:order].to_sym => :desc)

    table = [['#', 'name', 'logs']] # header
    tags.each do |tag|
        table << [tag.id, tag.tag, tag.logs.count] # row
    end
    print_table table
end

#rm(tag) ⇒ Object

option :prune, :type => :boolean, :alias => ‘-p’, :default => false not implemented yet



19
20
21
22
23
# File 'lib/subcommands/tags.rb', line 19

def rm(tag)
    tag = ::Tag.find_by!(tag: tag)
    tag.destroy
    say ["Tag", tag.tag, "destroyed forever"].join(' '), :green
end