settings_validation_wrapper.rb revision e2586f58230ac2938db5ee91191108988b206e2f
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekclass SettingsValidationWrapper
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek include ActiveModel::Validations
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek include SettingsValidationWrapper::Validators
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
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_PATH = `which nproc`
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek NPROC_AVAILABLE = NPROC_PATH.present? && File.executable?(NPROC_PATH)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek PRESENCE = %i(yml__name
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__OMS
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__OMS_qualifier
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__delivery_method
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__smtp_settings__address
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__allow_unconfirmed_access_for_days
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__max_read_filesize
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__max_combined_diff_size
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__ontology_parse_timeout
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__footer
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__exception_notifier__email_prefix
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__exception_notifier__sender_address
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__exception_notifier__exception_recipients
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__data
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__git_repositories
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__symlinks
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__commits
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__verify_url
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__default_branch
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__push_priority__commits
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__push_priority__changed_files_per_commit
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__fallbacks__committer_name
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__fallbacks__committer_email
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__allowed_iri_schemes
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__external_repository_name
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__formality_levels
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__license_models
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__ontology_types
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__tasks
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__version_minimum_version
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__version_minimum_revision
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__stack_size
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__cmd_line_options
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__server_options
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__env__LANG
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__fqdn
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__data_root
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__git_home
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__git_root
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__symlink_path
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__commits_path)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek PRESENCE_IN_PRODUCTION = %i(yml__hets__executable_path
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__instances_count)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek BOOLEAN = %i(yml__exception_notifier__enabled
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__display_head_commit
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__display_symbols_tab
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__format_selection
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__perform_deliveries
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__raise_delivery_errors
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__smtp_settings__enable_starttls_auto
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__consider_all_requests_local)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek FIXNUM = %i(yml__hets__instances_count
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__smtp_settings__port
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__allow_unconfirmed_access_for_days
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__push_priority__commits
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__push_priority__changed_files_per_commit
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__version_minimum_revision)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek FLOAT = %i(yml__hets__version_minimum_version)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek STRING = %i(yml__name
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__OMS
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__OMS_qualifier
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__email
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__action_mailer__smtp_settings__address
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__exception_notifier__email_prefix
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__exception_notifier__sender_address
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__data
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__git_repositories
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__symlinks
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__paths__commits
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__verify_url
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__default_branch
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__fallbacks__committer_name
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__git__fallbacks__committer_email
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__external_repository_name)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY = %i(yml__footer
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__exception_notifier__exception_recipients
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__allowed_iri_schemes
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__formality_levels
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__license_models
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__ontology_types
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__tasks
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__cmd_line_options
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__server_options)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek DIRECTORY_PRODUCTION = %i(initializers__data_root
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__git_home
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__git_root
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__symlink_path
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek initializers__commits_path)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ELEMENT_PRESENT = %i(yml__allowed_iri_schemes
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__cmd_line_options
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek yml__hets__server_options)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates_presence_of *PRESENCE
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates_presence_of *PRESENCE_IN_PRODUCTION, if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek BOOLEAN.each do |field|
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates field, class: {in: [TrueClass, FalseClass]}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
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 DIRECTORY_PRODUCTION.each do |field|
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates field, directory: true, if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ELEMENT_PRESENT.each { |field| validates field, elements_are_present: true }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :initializers__secret_token,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek presence: true,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek length: {minimum: 64},
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__email,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek email_from_host: {hostname: ->(record) { record.initializers__fqdn }},
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__exception_notifier__exception_recipients,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_are_email: true
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__action_mailer__delivery_method,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek inclusion: {in: %i(sendmail smtp file test)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__allow_unconfirmed_access_for_days,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek numericality: {greater_than_or_equal_to: 0}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
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__commits,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek numericality: {greater_than_or_equal_to: 1}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__git__push_priority__changed_files_per_commit,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek numericality: {greater_than_or_equal_to: 1}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__footer, elements_have_keys: {keys: %i(text)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__formality_levels,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_have_keys: {keys: %i(name description)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__license_models, elements_have_keys: {keys: %i(name url)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__ontology_types,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_have_keys: {keys: %i(name description documentation)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__tasks,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek elements_have_keys: {keys: %i(name description)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :initializers__log_level,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek inclusion: {in: %i(fatal error warn info debug)}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__hets__executable_path, executable: true, if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if NPROC_AVAILABLE
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__hets__instances_count,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek numericality: {greater_than: 0,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek less_than_or_equal_to: `nproc`.to_i},
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek else
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek validates :yml__hets__instances_count,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek numericality: {greater_than: 0},
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if: :in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek protected
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek def in_production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Rails.env.production?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
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 # underscores.
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 def method_missing(method_name, *_args)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek portions = method_name.to_s.split('__')
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek object = base(portions[0])
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek key_chain = portions[1..-1]
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if object == :error || key_chain.blank?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek raise NoMethodError,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek "undefined method `#{method_name}' for #{self}:#{self.class}"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek get_value(object, key_chain)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek def base(first_portion)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek case first_portion
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek when 'yml'
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Settings
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek when 'initializers'
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Ontohub::Application.config
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek else
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek :error
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek def get_value(object, key_chain)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek key_chain.each do |key|
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if object.respond_to?(key)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek object = object.send(key)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek else
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek # The nil value shall be caught by the presence validators.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return nil
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek object
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek end
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekend
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek