Sha256: 7fc18e2d6dbd80fc6ba050e49ae633c35e0fc428b099b9d1114e3599c9fec721

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module Sct
    class SctFolder
        FOLDER_NAME = "sct"

        def self.path 
            value ||= "./#{FOLDER_NAME}/" if File.directory?("./#{FOLDER_NAME}/")
            value ||= "./.#{FOLDER_NAME}/" if File.directory?("./.#{FOLDER_NAME}/") # hidden folder
            value ||= "./" if File.basename(Dir.getwd) == FOLDER_NAME && File.exist?('Sctfile') # inside the folder
            value ||= "./" if File.basename(Dir.getwd) == ".#{FOLDER_NAME}" && File.exist?('Sctfile') # inside the folder and hidden
            return value
        end

        def self.Sctfile_path
            return nil if self.path.nil?
      
            path = File.join(self.path, 'Sctfile')
            return path if File.exist?(path)
            return nil
        end

        # Does a Sct configuration already exist?
        def self.setup?
            return false unless self.Sctfile_path
            File.exist?(self.Sctfile_path)
        end

        def self.create_folder!(path = nil)
            path = File.join(path || '.', FOLDER_NAME)
            return if File.directory?(path) # directory is already there
            puts "Found a folder called 'Sct' at path '#{path}', please delete it" if File.exist?(path)
            FileUtils.mkdir_p(path)
            puts "Created new folder '#{path}'."
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sct-0.1.1 lib/sct/sct_folder.rb