lib/i18n/tasks/scanners/base_scanner.rb in i18n-tasks-0.6.2 vs lib/i18n/tasks/scanners/base_scanner.rb in i18n-tasks-0.6.3

- old
+ new

@@ -35,13 +35,13 @@ @key_filter = value @key_filter_pattern = compile_key_pattern(value) if @key_filter end # @return [Array<{key,data:{source_locations:[]}}] - def keys + def keys(opts = {}) keys = traverse_files { |path| - scan_file(path) + scan_file(path, opts) }.reduce(:+) || [] keys.group_by(&:first).map { |key, key_loc| [key, data: {source_locations: key_loc.map { |(k, attr)| attr[:data] }}] } end @@ -51,11 +51,11 @@ File.open(path, 'rb') { |f| result = f.read } result end # @return [Array<Key>] keys found in file - def scan_file(path, *args) + def scan_file(path, opts = {}) raise 'Unimplemented' end # Run given block for every relevant file, according to config # @return [Array] Results of block calls @@ -114,12 +114,18 @@ key = key[1..-2] if %w(' ").include?(key[0]) key end VALID_KEY_RE = /^[-\w.\#{}]+$/ + VALID_KEY_RE_STRICT = /^[-\w.]+$/ - def valid_key?(key) - key =~ VALID_KEY_RE && !(@key_filter && @key_filter_pattern !~ key) + def valid_key?(key, strict = false) + return false if @key_filter && @key_filter_pattern !~ key + if strict + key =~ VALID_KEY_RE_STRICT && !key.end_with?('.') + else + key =~ VALID_KEY_RE + end end def relative_roots config[:relative_roots] end