Module: RubyHome::Persistable::ClassMethods
- Defined in:
- lib/ruby_home/persistable.rb
Instance Method Summary collapse
- #create(**options) ⇒ Object
- #persist ⇒ Object
- #persisted ⇒ Object
- #read ⇒ Object
- #read_persisted ⇒ Object
- #reset ⇒ Object
- #write(collection) ⇒ Object
Instance Method Details
#create(**options) ⇒ Object
18 19 20 |
# File 'lib/ruby_home/persistable.rb', line 18 def create(**) new(**).tap(&:save) end |
#persist ⇒ Object
29 30 31 |
# File 'lib/ruby_home/persistable.rb', line 29 def persist File.write(source, cache.to_yaml) end |
#persisted ⇒ Object
12 13 14 15 16 |
# File 'lib/ruby_home/persistable.rb', line 12 def persisted if (yaml = read) new(**yaml) end end |
#read ⇒ Object
39 40 41 |
# File 'lib/ruby_home/persistable.rb', line 39 def read self.cache ||= read_persisted end |
#read_persisted ⇒ Object
33 34 35 36 37 |
# File 'lib/ruby_home/persistable.rb', line 33 def read_persisted YAML.load_file(source) rescue Errno::ENOENT false end |
#reset ⇒ Object
43 44 45 46 |
# File 'lib/ruby_home/persistable.rb', line 43 def reset self.cache = nil persist end |
#write(collection) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ruby_home/persistable.rb', line 22 def write(collection) self.cache = collection persist true end |