Class: Shh::Command::ListEntries

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, io) ⇒ ListEntries

Returns a new instance of ListEntries.



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

def initialize repository, io
  @repository, @io = repository, io
  @usage = "(<substring>)"
  @help = "Lists all entries or those with a name including the specified substring"
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



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

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



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

def usage
  @usage
end

Instance Method Details

#execute(text = nil) ⇒ Object



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

def execute text=nil
  @repository.each do |entry|
    unless entry.id == entry['id']
      puts "Encryption failure! Did you enter the correct password?"
      return
    end
  end
  @repository.sort{|l,r| (l['name']) <=> (r['name'])}.each do |entry|
    description = "#{entry['name']} (#{entry.id})"
    next if text and !(description =~ /#{text}/)
    @io.say description
  end
end