Class: Xampl::FilesystemPersister
Instance Attribute Summary
Attributes inherited from Persister
#automatic, #block_changes, #cache_hits, #format, #last_write_count, #name, #read_count, #rolled_back, #syncing, #total_cache_hits, #total_read_count, #total_rollback_count, #total_sync_count, #total_write_count, #write_count
Class Method Summary
collapse
Instance Method Summary
collapse
#cache, #clear_cache, #dump, #fresh_cache, #read, #read_from_cache, #rollback_cleanup, #sync_done, #uncache, #write_to_cache
Methods inherited from Persister
#busy, #cache, #clear_cache, #close, #count_changed, #do_sync_write, #find_known, #find_xampl, #has_changed, #has_not_changed, #introduce, #is_busy, #lazy_load, #lookup, #optimise, #print_stats, #put_changed, #query_implemented, #read, #realise, replace, #represent, #rollback, #rollback_cleanup, #sync, #sync_done, #uncache
Constructor Details
#initialize(name = nil, format = nil, root = File.join(".", "repo")) ⇒ FilesystemPersister
Returns a new instance of FilesystemPersister.
10
11
12
|
# File 'lib/xamplr/persisters/filesystem.rb', line 10
def initialize(name=nil, format=nil, root=File.join(".", "repo"))
super(root, name, format)
end
|
Class Method Details
.kind ⇒ Object
14
15
16
|
# File 'lib/xamplr/persisters/filesystem.rb', line 14
def FilesystemPersister.kind
:filesystem
end
|
Instance Method Details
#read_representation(klass, pid) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/xamplr/persisters/filesystem.rb', line 49
def read_representation(klass, pid)
place = File.join(@root_dir, klass.name.split("::"), pid)
return nil unless File.exist?(place)
representation = File.read(place)
return representation
end
|
#version(stream) ⇒ Object
22
23
24
25
26
|
# File 'lib/xamplr/persisters/filesystem.rb', line 22
def version(stream)
catch(:refuse_to_version) do
Version.new(@repo_name, @repo_root).make(stream)
end
end
|
#write(xampl) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/xamplr/persisters/filesystem.rb', line 29
def write(xampl)
raise XamplException.new("no_index_so_no_persist [#{xampl.class.name}]") unless xampl.get_the_index or xampl.ignore_when_no_index
return unless xampl.get_the_index
place = File.join(@root_dir, xampl.class.name.split("::"))
FileUtils.mkdir_p(place) unless File.exist?(place)
place = File.join(place, xampl.get_the_index)
representation = represent(xampl)
if representation then
File.open(place, "w"){ | out | out.puts representation }
@write_count = @write_count + 1
end
xampl.changes_accepted
return true
end
|