lib/i18n/tasks/configuration.rb in i18n-tasks-0.5.4 vs lib/i18n/tasks/configuration.rb in i18n-tasks-0.6.0
- old
+ new
@@ -11,12 +11,21 @@
i18n-tasks.yml i18n-tasks.yml.erb
)
def file_config
file = CONFIG_FILES.detect { |f| File.exists?(f) }
- file = YAML.load(Erubis::Eruby.new(File.read(file)).result) if file
- {}.with_indifferent_access.merge(file.presence || {})
+ config = file && YAML.load(Erubis::Eruby.new(File.read(file)).result)
+ if config.present?
+ config.with_indifferent_access.tap do |c|
+ if c[:relative_roots]
+ warn_deprecated 'config/i18n-tasks.yml has relative_roots on top level. Please move relative_roots under search.'
+ c[:search][:relative_roots] = c.delete(:relative_roots)
+ end
+ end
+ else
+ {}.with_indifferent_access
+ end
end
def config=(conf)
@config = file_config.deep_merge(conf)
@config_sections = {}
@@ -32,14 +41,10 @@
config: data.config
}
end
end
- def relative_roots
- @config_sections[:relative_roots] ||= config[:relative_roots].presence || %w(app/views)
- end
-
# translation config
# @return [Hash{String => String,Hash,Array}]
def translation_config
@config_sections[:translation] ||= begin
conf = (config[:translation] || {}).with_indifferent_access
@@ -73,34 +78,30 @@
end
locales
end
end
- def non_base_locales(from = nil)
- from ||= self.locales
- Array(from) - [base_locale]
- end
-
# @return [String] default i18n locale
def base_locale
@config_sections[:base_locale] ||= (config[:base_locale] || 'en').to_s
end
+
def ignore_config(type = nil)
key = type ? "ignore_#{type}" : 'ignore'
@config_sections[key] ||= config[key]
end
+ IGNORE_TYPES = [nil, :missing, :unused, :eq_base].freeze
# evaluated configuration (as the app sees it)
def config_sections
# init all sections
base_locale
locales
data_config
search_config
- relative_roots
translation_config
- [nil, :missing, :unused, :eq_base].each do |ignore_type|
+ IGNORE_TYPES.each do |ignore_type|
ignore_config ignore_type
end
@config_sections
end