settings_validation_wrapper.rb revision e2586f58230ac2938db5ee91191108988b206e2f
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # We assume that deployment is done on a linux machine that has 'nproc'.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # Counting processors is different on other machines. For them, we would need
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # to use a gem.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek NPROC_AVAILABLE = NPROC_PATH.present? && File.executable?(NPROC_PATH)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__push_priority__changed_files_per_commit
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek PRESENCE_IN_PRODUCTION = %i(yml__hets__executable_path
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__smtp_settings__enable_starttls_auto
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__push_priority__changed_files_per_commit
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek DIRECTORY_PRODUCTION = %i(initializers__data_root
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates_presence_of *PRESENCE_IN_PRODUCTION, if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates field, class: {in: [TrueClass, FalseClass]}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek FIXNUM.each { |field| validates field, class: {in: [Fixnum]} }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek FLOAT.each { |field| validates field, class: {in: [Float]} }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek STRING.each { |field| validates field, class: {in: [String]} }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY.each { |field| validates field, class: {in: [Array]} }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates field, directory: true, if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ELEMENT_PRESENT.each { |field| validates field, elements_are_present: true }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek email_from_host: {hostname: ->(record) { record.initializers__fqdn }},
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__exception_notifier__exception_recipients,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__action_mailer__delivery_method,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__allow_unconfirmed_access_for_days,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__max_read_filesize, numericality: {greater_than: 1024}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__max_combined_diff_size, numericality: {greater_than: 2048}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__ontology_parse_timeout, numericality: {greater_than: 0}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__git__verify_url, format: URI.regexp
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__git__push_priority__changed_files_per_commit,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__footer, elements_have_keys: {keys: %i(text)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_have_keys: {keys: %i(name description)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__license_models, elements_have_keys: {keys: %i(name url)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_have_keys: {keys: %i(name description documentation)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_have_keys: {keys: %i(name description)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek inclusion: {in: %i(fatal error warn info debug)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__hets__executable_path, executable: true, if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # We use '__' as a separator. It will be replaced by a dot.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # This uses the fact that our settings-keys never have two consecutive
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # yml__git__verify_url maps to Settings.git.verify_url.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # initializers__git__verify_url maps to @config.git.verify_url.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek "undefined method `#{method_name}' for #{self}:#{self.class}"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # The nil value shall be caught by the presence validators.