Module: Dsu::Support::ProjectFileSystem::ClassMethods
- Includes:
- Fileable
- Defined in:
- lib/dsu/support/project_file_system.rb
Constant Summary
Constants included from Fileable
Fileable::MIGRATION_VERSION_FILE_NAME
Instance Method Summary collapse
-
#current_project_file_exist? ⇒ Boolean
(also: #current_project_file_persisted?)
Does dsu/current_project.json file exist?.
-
#current_project_name ⇒ Object
Returns the currently selected (used) project name from dsu/current_project.json.
- #default_project_name ⇒ Object
- #initialize_project(project_name:) ⇒ Object
-
#project_file_exist?(project_name:) ⇒ Boolean
(also: #exist?, #persisted?)
Does dsu/projects/<project_name>/project.json file exist?.
-
#project_folder_exist?(project_name:) ⇒ Boolean
Does dsu/projects/<project_name> folder exist?.
- #project_initialized?(project_name:) ⇒ Boolean
- #project_metadata ⇒ Object
- #project_number_for(project_name:) ⇒ Object
Methods included from Fileable
#backup_folder_for, #config_file_name, #config_folder, #config_path, #current_project_file, #current_project_file_name, #dsu_folder, #entries_file_name, #entries_folder, #entries_path, #gem_dir, #migration_version_folder, #migration_version_path, #project_file_for, #project_folder_for, #projects_folder, #root_folder, #seed_data_dsu_configuration_for, #seed_data_dsu_folder_for, #temp_folder, #theme_file_name, #themes_folder, #themes_path
Instance Method Details
#current_project_file_exist? ⇒ Boolean Also known as: current_project_file_persisted?
Does dsu/current_project.json file exist?
78 79 80 |
# File 'lib/dsu/support/project_file_system.rb', line 78 def current_project_file_exist? File.exist?(current_project_file) end |
#current_project_name ⇒ Object
Returns the currently selected (used) project name from dsu/current_project.json
37 38 39 |
# File 'lib/dsu/support/project_file_system.rb', line 37 def current_project_name Crud::JsonFile.read!(file_path: current_project_file).fetch(:project_name) end |
#default_project_name ⇒ Object
41 42 43 44 45 |
# File 'lib/dsu/support/project_file_system.rb', line 41 def default_project_name return Models::Configuration::DEFAULT_CONFIGURATION[:default_project] unless Models::Configuration.exist? Models::Configuration.new.default_project end |
#initialize_project(project_name:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dsu/support/project_file_system.rb', line 47 def initialize_project(project_name:) return if project_initialized?(project_name: project_name) # TODO: Don't know if I like this here. unless current_project_file_exist? file_data = { version: Dsu::Migration::VERSION, project_name: default_project_name } Crud::JsonFile.write!(file_data: file_data, file_path: current_project_file) end # Creates dsu/projects/<project_name> FileUtils.mkdir_p(project_folder_for(project_name: project_name)) end |
#project_file_exist?(project_name:) ⇒ Boolean Also known as: exist?, persisted?
Does dsu/projects/<project_name>/project.json file exist?
70 71 72 73 |
# File 'lib/dsu/support/project_file_system.rb', line 70 def project_file_exist?(project_name:) project_file_path = project_file_for(project_name: project_name) File.exist?(project_file_path) end |
#project_folder_exist?(project_name:) ⇒ Boolean
Does dsu/projects/<project_name> folder exist?
84 85 86 |
# File 'lib/dsu/support/project_file_system.rb', line 84 def project_folder_exist?(project_name:) Dir.exist?(project_folder_for(project_name: project_name)) end |
#project_initialized?(project_name:) ⇒ Boolean
63 64 65 66 67 |
# File 'lib/dsu/support/project_file_system.rb', line 63 def project_initialized?(project_name:) # Checking these files, checks all the containing folders also current_project_file_exist? && project_folder_exist?(project_name: project_name) end |
#project_metadata ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dsu/support/project_file_system.rb', line 88 def project_folder_names.each_with_index.with_object([]) do |(project_name, index), array| array << { project_number: index + 1, project_name: project_name, current_project: project_name == current_project_name, default_projet: project_name == default_project_name } end end |
#project_number_for(project_name:) ⇒ Object
99 100 101 102 103 |
# File 'lib/dsu/support/project_file_system.rb', line 99 def project_number_for(project_name:) .find do || [:project_name] == project_name end&.[](:project_number) || -1 end |