Class: TT::I18nSync

Inherits:
Object
  • Object
show all
Defined in:
lib/t_t/i18n_sync.rb

Defined Under Namespace

Modules: Utils Classes: FileGroup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(st_locale, files, mark) ⇒ I18nSync



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/t_t/i18n_sync.rb', line 107

def initialize(st_locale, files, mark)
  @groups = []

  files.inject({}) do |r, file|
    parts = file.split('.')
    k = parts[0...-2].join('.')
    l = File.basename(parts[-2])
    r[k] ||= {}
    r[k][l] = file
    r
  end.each_value do |group|
    locales = group.keys
    next unless locales.include?(st_locale) && locales.size > 1
    list = group.reject { |l, v| l == st_locale }
    groups << FileGroup.new(st_locale, group[st_locale], list, mark)
  end

  @checker = ActiveSupport::FileUpdateChecker.new(groups.map(&:standard)) { execute }
end

Instance Attribute Details

#checkerObject (readonly)

Returns the value of attribute checker.



105
106
107
# File 'lib/t_t/i18n_sync.rb', line 105

def checker
  @checker
end

#groupsObject (readonly)

Returns the value of attribute groups.



105
106
107
# File 'lib/t_t/i18n_sync.rb', line 105

def groups
  @groups
end

Instance Method Details

#executeObject



127
128
129
# File 'lib/t_t/i18n_sync.rb', line 127

def execute
  groups.each(&:execute)
end

#missedObject



131
132
133
134
135
136
137
138
139
140
# File 'lib/t_t/i18n_sync.rb', line 131

def missed
  groups.inject({}) do |r, group|
    unless (list = group.missed).empty?
      base_path = group.standard.split(group.st_locale)[0]
      key = "#{ base_path }(*).yml"
      r[key] = list
    end
    r
  end
end