Class: Gtool::Provision::Nickname

Inherits:
Thor
  • Object
show all
Includes:
Util
Defined in:
lib/gtool/provision/nickname.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#ask_default

Class Method Details



62
63
64
# File 'lib/gtool/provision/nickname.rb', line 62

def self.banner(task, namespace = true, subcommand = false)
  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
end

Instance Method Details

#create(username, nickname) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gtool/provision/nickname.rb', line 50

def create(username, nickname)
  connection = Gtool::Auth.connection(options)

  nick = GProv::Provision::Nickname.new(:connection => connection)
  nick. = username
  nick.nickname = nickname

  nick.create!

  invoke "user:nickname:get", [nickname]
end

#get(username) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gtool/provision/nickname.rb', line 34

def get(username)
  connection = Gtool::Auth.connection(options)
  nicknames = GProv::Provision::Nickname.all(connection, options.merge(:username => username))
  fields = GProv::Provision::Nickname.attribute_names
  field_names = GProv::Provision::Nickname.attribute_titles

  rows = nicknames.map do |nickname|
    fields.map {|f| nickname.send f}
  end

  rows.unshift field_names
  print_table rows
  say "#{rows.length - 1} entries.", :cyan
end

#listObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gtool/provision/nickname.rb', line 18

def list
  connection = Gtool::Auth.connection(options)
  nicknames = GProv::Provision::Nickname.all(connection, options)
  fields = GProv::Provision::Nickname.attribute_names
  field_names = GProv::Provision::Nickname.attribute_titles

  rows = nicknames.map do |nickname|
    fields.map {|f| nickname.send f}
  end

  rows.unshift field_names
  print_table rows
  say "#{rows.length - 1} entries.", :cyan
end