Sha256: 2cc5ef83b9eab3c25ebf9863bc6bc3e3704bef20fc93713a2327b0ed6d3b4fa6

Contents?: true

Size: 1.92 KB

Versions: 18

Compression:

Stored size: 1.92 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2022 Eric Crane.  All rights reserved.
#
# Disc based mechanism for files.
# Provides interaction between the persistance classes and the OS 
# file and folder system.
# This class might be overiden elsewhere to provide other mechanism.
# For example, in gloo-web, there will be a db based mechanism.
#

module Gloo
  module Persist
    class DiscMech

      #
      # Set up a disc based file mechanism.
      #
      def initialize( engine )
        @engine = engine
      end

      #
      # Get the default file extention.
      #
      def file_ext
        return '.gloo'
      end

      #
      # Get all the gloo files in the folder (partial path).
      #
      def get_all_files_in( folder )
        pns = []
        dir = File.join( @engine.settings.project_path, folder )
        Dir.glob( "#{dir}*.gloo" ).each do |f|
          pns << f
        end
        return pns
      end

      # 
      # Check if a file exists.
      # 
      def exist?( file )
        File.exist?( file )
      end

      # 
      # Check to see if the file is valid.
      # 
      def valid?( file )
        return false unless file
        return false unless File.exist?( file )
        return false unless File.file?( file )
        return false unless file.end_with?( self.file_ext )

        return true
      end

      # 
      # Expand a single file path.
      # 
      def expand( name )
        ext_path = File.expand_path( name )
        return [ ext_path ] if self.valid?( ext_path )

        full_name = "#{name}#{file_ext}"
        return [ File.join( @engine.settings.project_path, full_name ) ]
      end

      # 
      # Read in the contents of a single file.
      # 
      def read( file )
        return File.read( file )
      end

      # 
      # Write data to the file.
      # 
      def write( pn, data )
        File.write( pn, data )
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gloo-3.4.0 lib/gloo/persist/disc_mech.rb
gloo-3.3.0 lib/gloo/persist/disc_mech.rb
gloo-3.2.0 lib/gloo/persist/disc_mech.rb
gloo-3.1.1 lib/gloo/persist/disc_mech.rb
gloo-3.1.0 lib/gloo/persist/disc_mech.rb
gloo-3.0.1 lib/gloo/persist/disc_mech.rb
gloo-3.0.0 lib/gloo/persist/disc_mech.rb
gloo-2.5.0 lib/gloo/persist/disc_mech.rb
gloo-2.4.3 lib/gloo/persist/disc_mech.rb
gloo-2.4.2 lib/gloo/persist/disc_mech.rb
gloo-2.4.1 lib/gloo/persist/disc_mech.rb
gloo-2.4.0 lib/gloo/persist/disc_mech.rb
gloo-2.3.1 lib/gloo/persist/disc_mech.rb
gloo-2.2.0 lib/gloo/persist/disc_mech.rb
gloo-2.1.0 lib/gloo/persist/disc_mech.rb
gloo-2.0.2 lib/gloo/persist/disc_mech.rb
gloo-2.0.1 lib/gloo/persist/disc_mech.rb
gloo-2.0.0 lib/gloo/persist/disc_mech.rb