Class: Commands::Block

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

Constant Summary collapse

Label =
"blocked"
MessagePrefix =
"Blocked:"

Instance Attribute Summary

Attributes inherited from Base

#input, #options, #output

Instance Method Summary collapse

Methods inherited from Base

#get, #put, #sys, #with

Constructor Details

#initialize(*args) ⇒ Block

Returns a new instance of Block.



8
9
10
11
# File 'lib/commands/block.rb', line 8

def initialize(*args)
  @story_id = args.shift if args.first =~ /^(\d+)$/
  super(*args)
end

Instance Method Details

#run!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commands/block.rb', line 13

def run!
  super

  unless story_id
    put "No story id was supplied and you aren't on a topic branch!"
    return 1
  end
  
  if story.labels.to_s.include?(Label)
    put "Story #{story_id} is already blocked."
    return 0
  end
  
  message = options[:message].to_s

  if message.empty?
    loop do
      put "What's the reason for blocking this story?"
      message = input.gets.chomp
      break unless message.empty?
      put ""
    end
  end
  
  labels = story.labels.to_s.split(",").concat([Label]).join(",")
  story.update :labels => labels
  story.notes.create :author => full_name, :text => "#{MessagePrefix} #{message}"
  put "Story #{story_id} has been blocked."

  return 0
end