Class: Cloak::List

Inherits:
Object
  • Object
show all
Defined in:
lib/cloak/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeList

Returns a new instance of List.



11
12
13
14
15
# File 'lib/cloak/list.rb', line 11

def initialize
  @path = File.expand_path('~/.cloak')
  @entries = []
  load rescue save 
end

Instance Attribute Details

#entriesObject

Entries Array



9
10
11
# File 'lib/cloak/list.rb', line 9

def entries
  @entries
end

#pathObject (readonly)

List Path



5
6
7
# File 'lib/cloak/list.rb', line 5

def path
  @path
end

Instance Method Details

#add(entry) ⇒ Object Also known as: <<

Append entries to the array



19
20
21
# File 'lib/cloak/list.rb', line 19

def add(entry)
  @entries << entry
end

#loadObject

Load the all entries into the array



36
37
38
39
40
# File 'lib/cloak/list.rb', line 36

def load
  @entries = YAML.load_file path
  @entries = [] if !@entries
  self
end

#saveObject

Save all entries to the specified path



26
27
28
29
30
31
32
# File 'lib/cloak/list.rb', line 26

def save
  set_entry_encoding
  File.open(path, "wb") do |file|
    file.write YAML.dump(entries)
  end
  self
end