Class: Piggy::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/piggy/file_store.rb

Instance Method Summary collapse

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

#allObject



16
17
18
# File 'lib/piggy/file_store.rb', line 16

def all
  any? ? IO.readlines(store).map(&:chomp) : [] 
end

#any?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/piggy/file_store.rb', line 20

def any?
  store_exists?
end

#clearObject



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