Module: PhrasingPhrase::Serialize

Included in:
PhrasingPhrase
Defined in:
app/models/phrasing_phrase.rb

Instance Method Summary collapse

Instance Method Details

#export_yamlObject



47
48
49
50
51
52
53
54
# File 'app/models/phrasing_phrase.rb', line 47

def export_yaml
  hash = {}
  where("value is not null").each do |phrase|
    hash[phrase.locale] ||= {}
    hash[phrase.locale][phrase.key] = phrase.value
  end
  hash.to_yaml
end

#import_yaml(yaml) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/phrasing_phrase.rb', line 31

def import_yaml(yaml)
  number_of_changes = 0
  hash = YAML.load(yaml)
  hash.each do |locale, data|
    data.each do |key, value|
      phrase = where(key: key, locale: locale).first || new(key: key, locale: locale)
      if phrase.value != value
        phrase.value = value
        number_of_changes += 1
        phrase.save
      end
    end
  end
  number_of_changes
end