Class: Xampl::FilesystemPersister
- Inherits:
-
AbstractCachingPersister
- Object
- Persister
- AbstractCachingPersister
- Xampl::FilesystemPersister
- Defined in:
- lib/xamplr/persisters/filesystem.rb
Instance Attribute Summary
Attributes inherited from Persister
#automatic, #block_changes, #cache_hits, #expunged, #format, #last_write_count, #name, #read_count, #rolled_back, #slow_sync, #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
-
#initialize(name = nil, format = nil, root = nil) ⇒ FilesystemPersister
constructor
A new instance of FilesystemPersister.
- #kind ⇒ Object
- #read_representation(klass, pid) ⇒ Object
- #write(xampl) ⇒ Object
Methods inherited from AbstractCachingPersister
#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, #done_sync_write, #expunge, #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, #shutdown, #start_sync_write, #sync, #sync_done, #uncache
Constructor Details
#initialize(name = nil, format = nil, root = nil) ⇒ FilesystemPersister
Returns a new instance of FilesystemPersister.
8 9 10 11 12 13 14 |
# File 'lib/xamplr/persisters/filesystem.rb', line 8 def initialize(name=nil, format=nil, root=nil) root = File.join(".", "repo") if root.nil? super(root, name, format) @deliberate_sync = $is_darwin && (not Xampl.[:sloppy_sync]) end |
Class Method Details
.kind ⇒ Object
16 17 18 |
# File 'lib/xamplr/persisters/filesystem.rb', line 16 def FilesystemPersister.kind :filesystem end |
Instance Method Details
#kind ⇒ Object
20 21 22 |
# File 'lib/xamplr/persisters/filesystem.rb', line 20 def kind FilesystemPersister.kind end |
#read_representation(klass, pid) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/xamplr/persisters/filesystem.rb', line 53 def read_representation(klass, pid) place = File.join(@root_dir, klass.persistence_class.name.split("::"), pid) #place = File.join(@root_dir, klass.name.split("::"), pid) return nil unless File.exist?(place) representation = File.read(place) return representation end |
#write(xampl) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/xamplr/persisters/filesystem.rb', line 24 def write(xampl) #raise XamplException.new(:no_index_so_no_persist) unless xampl.get_the_index or xampl.ignore_when_no_index 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("::")) place = File.join(@root_dir, xampl.class.persistence_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") do |out| out.puts representation out.fsync #if $is_darwin then if @deliberate_sync then out.fcntl(51, 0) # Attempt an F_FULLFSYNC fcntl to commit data to disk end end @write_count = @write_count + 1 end xampl.changes_accepted return true end |