Class: InertiaI18n::ScanResults
- Inherits:
-
Object
- Object
- InertiaI18n::ScanResults
- Defined in:
- lib/inertia_i18n/scan_results.rb
Instance Attribute Summary collapse
-
#dynamic_patterns ⇒ Object
readonly
Returns the value of attribute dynamic_patterns.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#occurrences ⇒ Object
readonly
Returns the value of attribute occurrences.
-
#static_keys ⇒ Object
readonly
Returns the value of attribute static_keys.
Instance Method Summary collapse
- #add_file(file, keys) ⇒ Object
-
#initialize ⇒ ScanResults
constructor
A new instance of ScanResults.
- #to_h ⇒ Object
- #used_keys ⇒ Object
Constructor Details
#initialize ⇒ ScanResults
Returns a new instance of ScanResults.
7 8 9 10 11 12 |
# File 'lib/inertia_i18n/scan_results.rb', line 7 def initialize @files = {} @static_keys = Set.new @dynamic_patterns = [] @occurrences = Hash.new { |h, k| h[k] = [] } end |
Instance Attribute Details
#dynamic_patterns ⇒ Object (readonly)
Returns the value of attribute dynamic_patterns.
5 6 7 |
# File 'lib/inertia_i18n/scan_results.rb', line 5 def dynamic_patterns @dynamic_patterns end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/inertia_i18n/scan_results.rb', line 5 def files @files end |
#occurrences ⇒ Object (readonly)
Returns the value of attribute occurrences.
5 6 7 |
# File 'lib/inertia_i18n/scan_results.rb', line 5 def occurrences @occurrences end |
#static_keys ⇒ Object (readonly)
Returns the value of attribute static_keys.
5 6 7 |
# File 'lib/inertia_i18n/scan_results.rb', line 5 def static_keys @static_keys end |
Instance Method Details
#add_file(file, keys) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inertia_i18n/scan_results.rb', line 14 def add_file(file, keys) @files[file] = keys keys[:static].each do |usage| # Handle both legacy string keys and new usage objects if usage.is_a?(Hash) key = usage[:key] @static_keys.add(key) @occurrences[key] << {file: file, line: usage[:line]} else @static_keys.add(usage) @occurrences[usage] << {file: file, line: nil} end end config = InertiaI18n.configuration dynamic_keys_config = config.dynamic_keys || {} keys[:dynamic].each do |dynamic| pattern = dynamic[:pattern] @dynamic_patterns << dynamic if dynamic_keys_config.key?(pattern) dynamic_keys_config[pattern].each do |value| # Append value to pattern (e.g. "status." + "active" -> "status.active") = "#{pattern}#{value}" @static_keys.add() @occurrences[] << {file: file, line: dynamic[:line]} end end end end |
#to_h ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/inertia_i18n/scan_results.rb', line 51 def to_h { files: @files, static_keys: @static_keys.to_a, dynamic_patterns: @dynamic_patterns, occurrences: @occurrences } end |
#used_keys ⇒ Object
47 48 49 |
# File 'lib/inertia_i18n/scan_results.rb', line 47 def used_keys @static_keys end |