lib/dsu/models/configuration.rb in dsu-2.4.4 vs lib/dsu/models/configuration.rb in dsu-3.0.0.alpha.0
- old
+ new
@@ -40,28 +40,33 @@
include_all: false,
# Themes
# The currently selected color theme. Should be equal to
# Models::ColorTheme::DEFAULT_THEME_NAME or the name of a custom
# theme (with the same file name) that resides in the themes_folder.
- theme_name: 'default'
+ theme_name: 'default',
+ # The default project to use.
+ default_project: 'default'
}.freeze
validates_with Validators::VersionValidator
validates :editor, presence: true
validates :entries_display_order, presence: true,
inclusion: { in: %i[asc desc], message: 'must be :asc or :desc' }
validates :carry_over_entries_to_today, inclusion: { in: [true, false], message: 'must be true or false' }
validates :include_all, inclusion: { in: [true, false], message: 'must be true or false' }
validates :theme_name, presence: true
validate :validate_theme_file
+ validates :default_project, presence: true
+ validate :validate_default_project
attr_accessor :version,
:editor,
:entries_display_order,
:carry_over_entries_to_today,
:include_all,
- :theme_name
+ :theme_name,
+ :default_project
attr_reader :options
alias exist? file_exist?
@@ -112,11 +117,12 @@
version: version,
editor: editor,
entries_display_order: entries_display_order,
carry_over_entries_to_today: carry_over_entries_to_today,
include_all: include_all,
- theme_name: theme_name
+ theme_name: theme_name,
+ default_project: default_project
}
end
# Override == and hash so that we can compare objects based
# on attributes alone. This is also useful for comparing objects
@@ -148,17 +154,26 @@
DEFAULT_CONFIGURATION[:entries_display_order])
@carry_over_entries_to_today = config_hash.fetch(:carry_over_entries_to_today,
DEFAULT_CONFIGURATION[:carry_over_entries_to_today])
@include_all = config_hash.fetch(:include_all, DEFAULT_CONFIGURATION[:include_all])
@theme_name = config_hash.fetch(:theme_name, DEFAULT_CONFIGURATION[:theme_name])
+ @default_project = config_hash.fetch(:default_project, DEFAULT_CONFIGURATION[:default_project])
end
def validate_theme_file
theme_path = themes_path(theme_name: theme_name)
return if File.exist?(theme_path)
i18n_key = 'configuration.errors.theme_file_missing'
errors.add(:base, I18n.t(i18n_key, theme_path: theme_path))
+ end
+
+ def validate_default_project
+ default_project_folder = File.join(projects_folder, default_project.presence || '{{blank}}')
+ return if Dir.exist?(default_project_folder)
+
+ i18n_key = 'configuration.errors.project_path_missing'
+ errors.add(:base, I18n.t(i18n_key, project_folder: default_project_folder))
end
end
end
end