Module: RubyHome::Persistable::ClassMethods

Defined in:
lib/ruby_home/persistable.rb

Instance Method Summary collapse

Instance Method Details

#create(**options) ⇒ Object



13
14
15
# File 'lib/ruby_home/persistable.rb', line 13

def create(**options)
  new(**options).tap(&:save)
end

#persistedObject



9
10
11
# File 'lib/ruby_home/persistable.rb', line 9

def persisted
  new(read) if read
end

#readObject



21
22
23
24
25
# File 'lib/ruby_home/persistable.rb', line 21

def read
  return false unless File.exists?(source)

  YAML.load_file(source)
end

#write(collection) ⇒ Object



17
18
19
# File 'lib/ruby_home/persistable.rb', line 17

def write(collection)
  File.open(source, 'w') {|f| f.write(collection.to_yaml) }
end