Module: Dsu::Support::Fileable
- Extended by:
- Fileable
- Included in:
- CommandServices::AddEntryService, Migration::BaseService, Models::ColorTheme, Models::Configuration, Models::EntryGroup, Models::MigrationVersion, Models::Project, Dsu::Services::EntryGroup::ExporterService, Dsu::Services::EntryGroup::ImporterService, Fileable, ProjectFileSystem::ClassMethods
- Defined in:
- lib/dsu/support/fileable.rb
Constant Summary collapse
- MIGRATION_VERSION_FILE_NAME =
'migration_version.json'
Instance Method Summary collapse
-
#backup_folder_for(migration_version:) ⇒ Object
Backup folders.
- #config_file_name ⇒ Object
-
#config_folder ⇒ Object
Configuration.
- #config_path ⇒ Object
-
#current_project_file ⇒ Object
The complete path to the current project file.
-
#current_project_file_name ⇒ Object
Contains the name of the file that contains the current dsu project currently being used.
- #dsu_folder ⇒ Object
- #entries_file_name(time:, file_name_format: nil) ⇒ Object
-
#entries_folder ⇒ Object
Entries.
- #entries_path(time:, file_name_format: nil) ⇒ Object
- #gem_dir ⇒ Object
-
#migration_version_folder ⇒ Object
Migration.
- #migration_version_path ⇒ Object
- #project_file_for(project_name:) ⇒ Object (also: #project_file)
-
#project_folder_for(project_name:) ⇒ Object
(also: #project_folder)
Returns the path of the project with the given name.
-
#projects_folder ⇒ Object
Returns the folder where all the projects are stored.
-
#root_folder ⇒ Object
Base folders.
- #seed_data_dsu_configuration_for(migration_version:) ⇒ Object
-
#seed_data_dsu_folder_for(migration_version:) ⇒ Object
Seed data files and folders.
- #temp_folder ⇒ Object
- #theme_file_name(theme_name:) ⇒ Object
-
#themes_folder ⇒ Object
Themes.
- #themes_path(theme_name:) ⇒ Object
Instance Method Details
#backup_folder_for(migration_version:) ⇒ Object
Backup folders
129 130 131 |
# File 'lib/dsu/support/fileable.rb', line 129 def backup_folder_for(migration_version:) File.join(root_folder, "dsu-#{migration_version}-backup") end |
#config_file_name ⇒ Object
18 19 20 |
# File 'lib/dsu/support/fileable.rb', line 18 def config_file_name '.dsu' end |
#config_folder ⇒ Object
Configuration
14 15 16 |
# File 'lib/dsu/support/fileable.rb', line 14 def config_folder root_folder end |
#config_path ⇒ Object
22 23 24 |
# File 'lib/dsu/support/fileable.rb', line 22 def config_path File.join(config_folder, config_file_name) end |
#current_project_file ⇒ Object
The complete path to the current project file.
106 107 108 |
# File 'lib/dsu/support/fileable.rb', line 106 def current_project_file File.join(dsu_folder, current_project_file_name) end |
#current_project_file_name ⇒ Object
Contains the name of the file that contains the current dsu project currently being used.
101 102 103 |
# File 'lib/dsu/support/fileable.rb', line 101 def current_project_file_name 'current_project.json' end |
#dsu_folder ⇒ Object
8 9 10 |
# File 'lib/dsu/support/fileable.rb', line 8 def dsu_folder File.join(root_folder, 'dsu') end |
#entries_file_name(time:, file_name_format: nil) ⇒ Object
33 34 35 36 |
# File 'lib/dsu/support/fileable.rb', line 33 def entries_file_name(time:, file_name_format: nil) file_name_format ||= '%Y-%m-%d.json' time.strftime(file_name_format) end |
#entries_folder ⇒ Object
Entries
28 29 30 31 |
# File 'lib/dsu/support/fileable.rb', line 28 def entries_folder project_folder = project_folder_for(project_name: Models::Project.current_project_name) File.join(project_folder, 'entries') end |
#entries_path(time:, file_name_format: nil) ⇒ Object
38 39 40 |
# File 'lib/dsu/support/fileable.rb', line 38 def entries_path(time:, file_name_format: nil) File.join(entries_folder, entries_file_name(time: time, file_name_format: file_name_format)) end |
#gem_dir ⇒ Object
76 77 78 |
# File 'lib/dsu/support/fileable.rb', line 76 def gem_dir Gem.loaded_specs['dsu'].gem_dir end |
#migration_version_folder ⇒ Object
Migration
58 59 60 |
# File 'lib/dsu/support/fileable.rb', line 58 def migration_version_folder File.join(dsu_folder) end |
#migration_version_path ⇒ Object
62 63 64 |
# File 'lib/dsu/support/fileable.rb', line 62 def migration_version_path File.join(migration_version_folder, MIGRATION_VERSION_FILE_NAME) end |
#project_file_for(project_name:) ⇒ Object Also known as: project_file
120 121 122 123 124 |
# File 'lib/dsu/support/fileable.rb', line 120 def project_file_for(project_name:) project_folder = project_folder_for(project_name: project_name) File.join(project_folder, 'project.json') end |
#project_folder_for(project_name:) ⇒ Object Also known as: project_folder
Returns the path of the project with the given name.
113 114 115 116 117 |
# File 'lib/dsu/support/fileable.rb', line 113 def project_folder_for(project_name:) raise I18n.t('errors.project_name_invalid', project_name: '{{blank}}') if project_name.blank? File.join(projects_folder, project_name) end |
#projects_folder ⇒ Object
Returns the folder where all the projects are stored.
93 94 95 |
# File 'lib/dsu/support/fileable.rb', line 93 def projects_folder File.join(dsu_folder, 'projects') end |
#root_folder ⇒ Object
Base folders
68 69 70 |
# File 'lib/dsu/support/fileable.rb', line 68 def root_folder Dir.home end |
#seed_data_dsu_configuration_for(migration_version:) ⇒ Object
86 87 88 |
# File 'lib/dsu/support/fileable.rb', line 86 def seed_data_dsu_configuration_for(migration_version:) File.join(gem_dir, 'lib/seed_data', migration_version.to_s, '.dsu') end |
#seed_data_dsu_folder_for(migration_version:) ⇒ Object
Seed data files and folders
82 83 84 |
# File 'lib/dsu/support/fileable.rb', line 82 def seed_data_dsu_folder_for(migration_version:) File.join(gem_dir, 'lib/seed_data', migration_version.to_s, 'dsu') end |
#temp_folder ⇒ Object
72 73 74 |
# File 'lib/dsu/support/fileable.rb', line 72 def temp_folder Dir.tmpdir end |
#theme_file_name(theme_name:) ⇒ Object
52 53 54 |
# File 'lib/dsu/support/fileable.rb', line 52 def theme_file_name(theme_name:) "#{theme_name}.json" end |
#themes_folder ⇒ Object
Themes
44 45 46 |
# File 'lib/dsu/support/fileable.rb', line 44 def themes_folder File.join(dsu_folder, 'themes') end |
#themes_path(theme_name:) ⇒ Object
48 49 50 |
# File 'lib/dsu/support/fileable.rb', line 48 def themes_path(theme_name:) File.join(themes_folder, theme_file_name(theme_name: theme_name)) end |