Class: DiskStoragePlugin

Inherits:
Rubko::Storage show all
Defined in:
lib/rubko/plugins/storage/disk.rb

Instance Attribute Summary

Attributes included from Rubko::Base

#parent

Instance Method Summary collapse

Methods inherited from Rubko::Storage

#inspect, #to_s, #values

Methods inherited from Rubko::Plugin

#config

Methods included from Rubko::Base

#camelize, #finalize, #httpGet, #initialize, #jsonParse, #loadController, #loadFile, #loadModel, #loadPlugin, #loadView, #method_missing, #uncamelize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rubko::Base

Instance Method Details

#[](*path) ⇒ Object



21
22
23
24
# File 'lib/rubko/plugins/storage/disk.rb', line 21

def [](*path)
	data = File.read escape(path)+'/'+@name rescue return nil
	Marshal.load data rescue nil
end

#[]=(*path, val) ⇒ Object



26
27
28
29
30
31
# File 'lib/rubko/plugins/storage/disk.rb', line 26

def []=(*path, val)
	path = escape(path)
	FileUtils.mkpath path
	File.write path+'/'+@name, Marshal.dump(val)
	val
end

#initObject



6
7
8
9
# File 'lib/rubko/plugins/storage/disk.rb', line 6

def init
	@root = '.run/storage'
	@name = 'data.txt'
end

#keys(*path) ⇒ Object



33
34
35
36
37
# File 'lib/rubko/plugins/storage/disk.rb', line 33

def keys(*path)
	Dir[ escape(path)+'/*/' ].map { |key|
		unescape File.basename(key)
	}
end

#prune(*path) ⇒ Object



39
40
41
42
# File 'lib/rubko/plugins/storage/disk.rb', line 39

def prune(*path)
	FileUtils.rmtree escape(path), secure: true
	true
end

#rename(*path, name) ⇒ Object



44
45
46
47
48
49
# File 'lib/rubko/plugins/storage/disk.rb', line 44

def rename(*path, name)
	new = escape(path[0..-2] + [name])
	return false if File.exist? new
	FileUtils.mv escape(path), new
	true
end