Class: Remind101::Command::Groups

Inherits:
Base
  • Object
show all
Defined in:
lib/remind101/command/groups.rb

Overview

manage groups

Instance Method Summary collapse

Instance Method Details

#createObject

groups:create [NAME]

create a new group

-c, –code CODE # the group code (optional)

Examples

$ remind101 groups:create “Math 101” -c math101



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/remind101/command/groups.rb', line 39

def create
  name = shift_argument
  validate_arguments!

  attributes = { class_name: name }
  attributes[:code] = options[:code] if options[:code]

  group = action "Creating #{name}" do
    remind101.create_group! attributes
  end

  hputs([ group.name, group.class_name ].join(" | "))
end

#destroyObject

groups:destroy [CODE]

permanently destroy a group

Example:

$ remind101 groups:destroy math101 Destroying math101… done



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/remind101/command/groups.rb', line 62

def destroy
  code = shift_argument

  group = remind101.groups.find { |g| g.name == code }
  error("Unable to find a group with that code") if group.nil?

  message = "WARNING: Potentially Destructive Action\nThis command will destroy @#{code} (#{group.class_name})."
  if confirm_command(code, message)
    action("Destroying @#{code} (#{group.class_name})") do
      remind101.destroy_group!(group.id)
    end
  end
end

#indexObject

groups

list groups



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/remind101/command/groups.rb', line 10

def index
  validate_arguments!

  groups = remind101.groups

  if groups.empty?
    display "You have no groups"
  else
    styled_header "My Groups"
    styled_array groups.map { |g| [ g.name, g.class_name ] }
  end
end

#infoObject

groups:info [CODE]

show detailed group information



26
27
# File 'lib/remind101/command/groups.rb', line 26

def info
end