Class: Shh::Command::OpenEntry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, io) ⇒ OpenEntry

Returns a new instance of OpenEntry.



7
8
9
10
11
# File 'lib/shh/command/open_entry.rb', line 7

def initialize repository, io
  @repository, @io = repository, io
  @usage = "<entry name>"
  @help = "Enters a subshell for editing the specifed entry"
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



5
6
7
# File 'lib/shh/command/open_entry.rb', line 5

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



5
6
7
# File 'lib/shh/command/open_entry.rb', line 5

def usage
  @usage
end

Instance Method Details

#completion(text) ⇒ Object



13
14
15
# File 'lib/shh/command/open_entry.rb', line 13

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

#execute(name = nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/shh/command/open_entry.rb', line 17

def execute name=nil
  return unless name
  return if name.empty?
  entry = @repository.find { |entry| entry['name'] == name }
  entry ||= {'name' => name, 'id' => UUIDTools::UUID.random_create.to_s }
  Shh::EntryMenu.new(@io, entry).push
  @repository[entry['id']] = entry
end