Class: Piggy::FileStore
- Inherits:
-
Object
- Object
- Piggy::FileStore
- Defined in:
- lib/piggy/file_store.rb
Instance Method Summary collapse
- #all ⇒ Object
- #any? ⇒ Boolean
- #clear ⇒ Object
-
#initialize(store) ⇒ FileStore
constructor
A new instance of FileStore.
- #save(text) ⇒ Object
Constructor Details
#initialize(store) ⇒ FileStore
Returns a new instance of FileStore.
3 4 5 |
# File 'lib/piggy/file_store.rb', line 3 def initialize(store) @store = store end |
Instance Method Details
#all ⇒ Object
16 17 18 |
# File 'lib/piggy/file_store.rb', line 16 def all any? ? IO.readlines(store).map(&:chomp) : [] end |
#any? ⇒ Boolean
20 21 22 |
# File 'lib/piggy/file_store.rb', line 20 def any? store_exists? end |
#clear ⇒ Object
7 8 9 |
# File 'lib/piggy/file_store.rb', line 7 def clear delete_store if store_exists? end |
#save(text) ⇒ Object
11 12 13 14 |
# File 'lib/piggy/file_store.rb', line 11 def save(text) create_store unless store_exists? File.open(store, 'a') {|f| f.write(text + "\n") } end |