Class: DFC::PathHandler

Inherits:
Object show all

Overview

PathHandler 是用于专业模块下的工具,即 Core/专业/工具/PathHandler,方便快速获取子目录、创建用户目录

Instance Method Summary # collapse

Constructor Details

#initialize(path) ⇒ PathHandler

初始化 PathHandler

Examples:

module MyModule
 MyPathHandler = DFC::PathHandler.new(__FILE__)
end

Parameters:

  • path (String)

    路径,这个值不可变,永远都是 __FILE__

Version:

  • 2.1.2

Instance Method Details

#[](name) ⇒ String, Nil

通过标识获取子目录

:Data -> “Data”, 数据目录

:Ruby -> “Ruby”, ruby 源文件目录

:UI -> “UI”, UI 目录

Examples:

MyPathHandler[:Ruby]

Parameters:

  • name (Symbol)

    子目录标识

Returns:

  • (String, Nil)

Version:

  • 2.1.2

#get_path(*strings) ⇒ String, Nil Also known as: getPath

当前模块根目录以下获取路径(文件或文件夹),空参数则获取当前目录

Examples:

MyPathHandler.get_path(:Ruby, "main.rb")

Parameters:

  • strings (*<String, Symbol>)

    当参数为 Symbol 类型时,从 PathHandler#[] 取得路径名。

Returns:

  • (String, Nil)

    成功返回路径,失败返回 nil

Version:

  • 2.1.2

#get_user_data_path(*strings, &block) ⇒ String, Nil Also known as: getUserDataPath

创建、获取用户数据目录

Examples:

MyPathHandler.get_user_data_path("test1", "test2")
# 假设是在公共目录下开发,模块名为 MyModule
# -> C:/DFC_BIM/Data/User/Common/MyModule/test1/test2

Parameters:

  • strings (*String)

    文件夹名

Returns:

  • (String, Nil)

    成功获取或创建返回路径,失败返回 nil

Version:

  • 2.1.2