Class: Filebase::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/drivers/yaml.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ YAML

Returns a new instance of YAML.



7
8
9
# File 'lib/drivers/yaml.rb', line 7

def initialize( root )
  @root = root
end

Instance Method Details

#allObject



15
16
17
# File 'lib/drivers/yaml.rb', line 15

def all
  Dir[ path('*') ].map { |file| YAML.load( File.read( file ) ) }
end

#delete(key) ⇒ Object



27
28
29
# File 'lib/drivers/yaml.rb', line 27

def delete( key )
	FileUtils.remove( path( key ) )
end

#find(key) ⇒ Object



19
20
21
# File 'lib/drivers/yaml.rb', line 19

def find( key )
	( ::YAML.load( File.read( path( key ) ) ) if File.exists?( path( key ) ) ) || nil
end

#path(key) ⇒ Object



11
12
13
# File 'lib/drivers/yaml.rb', line 11

def path( key )
	@root / key + '.yml'
end

#save(key, object) ⇒ Object



23
24
25
# File 'lib/drivers/yaml.rb', line 23

def save( key, object )
	File.write( path( key ), object.to_yaml )
end