Sha256: 9ea2dd8c97f67085b043484060ed99b2eac35529b7a0f12686653150df8cf747

Contents?: true

Size: 1.93 KB

Versions: 16

Compression:

Stored size: 1.93 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 GlooLang
  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

16 entries across 16 versions & 1 rubygems

Version Path
gloo-lang-1.4.3 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.4.2 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.4.1 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.4.0 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.3.2 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.3.1 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.3.0 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.8 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.7 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.6 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.5 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.4 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.3 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.2 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.1 lib/gloo_lang/persist/disc_mech.rb
gloo-lang-1.2.0 lib/gloo_lang/persist/disc_mech.rb