Class: Ree::PathHelper
Constant Summary collapse
- SCHEMAS_FOLDER =
'schemas'
Class Method Summary collapse
-
.abs_object_path(object) ⇒ String
Absolute object file path.
-
.abs_object_schema_path(object) ⇒ String
Absolute object schema path.
-
.abs_package_dir(package) ⇒ String
Absolute package folder path (ex. /data/project/bc/accounts).
-
.abs_package_entry_path(package) ⇒ String
Absolute package entry path (ex. /data/project/bc/accounts/package/accounts.rb).
-
.abs_package_module_dir(package) ⇒ String
Absolute package folder path (ex. /data/project/bc/accounts/package/accounts).
-
.abs_package_schema_path(package) ⇒ String
Absolute package schema path.
-
.abs_package_schemas_dir(package) ⇒ String
Absolute package schemas folder path (ex. /data/project/bc/accounts/schemas).
-
.object_rpath(schema_rpath) ⇒ String
Relative path to a object source file (ex. bc/accounts/object.rb).
-
.object_schema_rpath(object_rpath) ⇒ String
Relative path of a object schema (ex. bc/accounts/schemas/accounts/object.schema.json).
-
.package_entry_path(schema_path) ⇒ String
Absolute or relative path of a package entry file (ex. bc/accounts/schemas/accounts.rb).
-
.package_name_from_dir(dir) ⇒ String
Name of package.
-
.package_relative_path(package, path) ⇒ String
File path relative to package (ex. accounts/entities/user.rb).
- .project_root_dir(package) ⇒ Object
Class Method Details
.abs_object_path(object) ⇒ String
Returns Absolute object file path.
11 12 13 14 |
# File 'lib/ree/core/path_helper.rb', line 11 def abs_object_path(object) package = Ree.container.packages_facade.get_package(object.package_name) File.join(project_root_dir(package), object.rpath) end |
.abs_object_schema_path(object) ⇒ String
Returns Absolute object schema path.
18 19 20 21 |
# File 'lib/ree/core/path_helper.rb', line 18 def abs_object_schema_path(object) package = Ree.container.packages_facade.get_package(object.package_name) File.join(project_root_dir(package), object.schema_rpath) end |
.abs_package_dir(package) ⇒ String
Returns Absolute package folder path (ex. /data/project/bc/accounts).
101 102 103 |
# File 'lib/ree/core/path_helper.rb', line 101 def abs_package_dir(package) File.join(project_root_dir(package), package.dir) end |
.abs_package_entry_path(package) ⇒ String
Returns Absolute package entry path (ex. /data/project/bc/accounts/package/accounts.rb).
73 74 75 |
# File 'lib/ree/core/path_helper.rb', line 73 def abs_package_entry_path(package) File.join(project_root_dir(package), package.entry_rpath) end |
.abs_package_module_dir(package) ⇒ String
Returns Absolute package folder path (ex. /data/project/bc/accounts/package/accounts).
79 80 81 82 83 |
# File 'lib/ree/core/path_helper.rb', line 79 def abs_package_module_dir(package) File.join( project_root_dir(package), package.dir, Ree::PACKAGE, package.name.to_s ) end |
.abs_package_schema_path(package) ⇒ String
Returns Absolute package schema path.
95 96 97 |
# File 'lib/ree/core/path_helper.rb', line 95 def abs_package_schema_path(package) File.join(project_root_dir(package), package.schema_rpath) end |
.abs_package_schemas_dir(package) ⇒ String
Returns Absolute package schemas folder path (ex. /data/project/bc/accounts/schemas).
87 88 89 90 91 |
# File 'lib/ree/core/path_helper.rb', line 87 def abs_package_schemas_dir(package) File.join( project_root_dir(package), package.dir, Ree::SCHEMAS ) end |
.object_rpath(schema_rpath) ⇒ String
Returns Relative path to a object source file (ex. bc/accounts/object.rb).
25 26 27 28 29 30 31 32 33 |
# File 'lib/ree/core/path_helper.rb', line 25 def object_rpath(schema_rpath) nodes = schema_rpath.split('/') index = nodes.index(SCHEMAS_FOLDER) nodes[index] = Ree::PACKAGE object_name = nodes[-1].split('.').first filename = "#{object_name}.rb" nodes[-1] = filename nodes.join('/') end |
.object_schema_rpath(object_rpath) ⇒ String
Returns Relative path of a object schema (ex. bc/accounts/schemas/accounts/object.schema.json).
37 38 39 40 41 42 43 44 45 |
# File 'lib/ree/core/path_helper.rb', line 37 def object_schema_rpath(object_rpath) nodes = object_rpath.split('/') index = nodes.index(Ree::PACKAGE) nodes[index] = Ree::SCHEMAS filename = File.basename(nodes[-1], '.*') schema_name = "#{filename}.#{Ree::SCHEMA}.json" nodes[-1] = schema_name nodes.join('/') end |
.package_entry_path(schema_path) ⇒ String
Returns Absolute or relative path of a package entry file (ex. bc/accounts/schemas/accounts.rb).
49 50 51 52 53 |
# File 'lib/ree/core/path_helper.rb', line 49 def package_entry_path(schema_path) dir = Pathname.new(schema_path).dirname.to_s name = dir.split('/').last File.join(dir, "#{Ree::PACKAGE}/#{name}.rb") end |
.package_name_from_dir(dir) ⇒ String
Returns name of package.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ree/core/path_helper.rb', line 57 def package_name_from_dir(dir) package_schema = File.join(dir, Ree::PACKAGE_SCHEMA_FILE) if File.exist?(package_schema) return package_schema.split('/')[-2] end if dir == '/' return nil end package_name_from_dir(File.('..', dir)) end |
.package_relative_path(package, path) ⇒ String
Returns File path relative to package (ex. accounts/entities/user.rb).
108 109 110 111 112 113 |
# File 'lib/ree/core/path_helper.rb', line 108 def package_relative_path(package, path) Pathname .new(path) .relative_path_from(File.join(Ree.root_dir, package.dir, Ree::PACKAGE)) .to_s end |