Sha256: 68d00f2d4b89498c54d8dd01292abcad8453d7fc3d9933e65da7d4d5bd3f2851
Contents?: true
Size: 1.5 KB
Versions: 16
Compression:
Stored size: 1.5 KB
Contents
module Xampl require 'xamplr/version' require "fileutils" require "xamplr/persisters/caching" class FilesystemPersister < AbstractCachingPersister def initialize(name=nil, format=nil, root=File.join(".", "repo")) super(root, name, format) end def FilesystemPersister.kind :filesystem end def kind FilesystemPersister.kind end def version(stream) catch(:refuse_to_version) do Version.new(@repo_name, @repo_root).make(stream) end end 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("::")) 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 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 end Xampl.register_persister_kind(FilesystemPersister) end
Version data entries
16 entries across 16 versions & 2 rubygems