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

Version Path
hutch-xamplr-1.1.0 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.1.1 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.1.2 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.1.4 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.2.0 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.0 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.1 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.10 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.11 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.12 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.13 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.14 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.3 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.8 lib/xamplr/persisters/filesystem.rb
hutch-xamplr-1.3.9 lib/xamplr/persisters/filesystem.rb
xamplr-1.2.0 lib/xamplr/persisters/filesystem.rb