Class: Cloak::List
- Inherits:
-
Object
- Object
- Cloak::List
- Defined in:
- lib/cloak/list.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Entries Array.
-
#path ⇒ Object
readonly
List Path.
Instance Method Summary collapse
-
#add(entry) ⇒ Object
(also: #<<)
Append entries to the array.
-
#initialize ⇒ List
constructor
A new instance of List.
-
#load ⇒ Object
Load the all entries into the array.
-
#save ⇒ Object
Save all entries to the specified path.
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
11 12 13 14 15 |
# File 'lib/cloak/list.rb', line 11 def initialize @path = File.('~/.cloak') @entries = [] load rescue save end |
Instance Attribute Details
#entries ⇒ Object
Entries Array
9 10 11 |
# File 'lib/cloak/list.rb', line 9 def entries @entries end |
#path ⇒ Object (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 |
#load ⇒ Object
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 |
#save ⇒ Object
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 |