Class: Shh::Command::ShowHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/shh/command/show_history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, io) ⇒ ShowHistory

Returns a new instance of ShowHistory.



4
5
6
7
8
# File 'lib/shh/command/show_history.rb', line 4

def initialize repository, io
  @repository, @io = repository, io
  @usage = "(<substring>)"
  @help = "Shows history for a given entry"
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



2
3
4
# File 'lib/shh/command/show_history.rb', line 2

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



2
3
4
# File 'lib/shh/command/show_history.rb', line 2

def usage
  @usage
end

Instance Method Details

#completion(text) ⇒ Object



10
11
12
# File 'lib/shh/command/show_history.rb', line 10

def completion text
  @repository.map{|entry| entry['name']}.grep(/^#{text}/).sort || []
end

#execute(name = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shh/command/show_history.rb', line 14

def execute name=nil
  entry = @repository.find { |entry| entry['name'] == name }
  id = entry ? entry.id : nil
  first = true
  @repository.history(id).each do |cs|
    puts '-------' unless first
    puts "#{cs.id} #{cs.time}"
    puts "#{cs.author}"
    puts "#{cs.description}"
    first = false
  end
end