Class: Lit::Source
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lit::Source
- Defined in:
- app/models/lit/source.rb
Constant Summary collapse
- LOCALES_PATH =
"/api/v1/locales.json"
- LOCALIZATION_KEYS_PATH =
"/api/v1/localization_keys.json"
- LOCALIZATIONS_PATH =
"/api/v1/localizations.json"
- LAST_CHANGE_PATH =
"/api/v1/last_change.json"
Instance Method Summary collapse
-
#api_key ⇒ Object
VALIDATIONS.
- #get_last_change ⇒ Object
-
#incomming_localizations ⇒ Object
ASSOCIATIONS.
- #synchronize ⇒ Object
- #touch_last_updated_at! ⇒ Object
Instance Method Details
#api_key ⇒ Object
VALIDATIONS
13 14 |
# File 'app/models/lit/source.rb', line 13 validates :api_key, :identifier, :url, :presence=>true |
#get_last_change ⇒ Object
27 28 29 30 |
# File 'app/models/lit/source.rb', line 27 def get_last_change result = get_from_remote(LAST_CHANGE_PATH) result["last_change"] unless result.nil? end |
#incomming_localizations ⇒ Object
ASSOCIATIONS
10 |
# File 'app/models/lit/source.rb', line 10 has_many :incomming_localizations |
#synchronize ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/lit/source.rb', line 32 def synchronize after = self.last_updated_at.nil? ? nil : self.last_updated_at.to_s(:db) result = get_from_remote(LOCALIZATIONS_PATH, {:after=>after}) unless result.nil? if result.is_a?(Array) result.each do |r| il = IncommingLocalization.new if ::Rails::VERSION::MAJOR<4 il = IncommingLocalization.where(:incomming_id=>r["id"]).first_or_initialize else il = IncommingLocalization.find_or_initialize_by(:incomming_id=>r["id"]) end il.source = self il.locale_str = r["locale_str"] il.locale = Locale.where(:locale=>il.locale_str).first il.localization_key_str = r["localization_key_str"] il.localization_key = LocalizationKey.where(:localization_key=>il.localization_key_str).first il.save! IncommingLocalization.where(:id=>il.id).update_all ['translated_value=?', r["value"]] end lc = get_last_change lc = DateTime.parse(lc) unless lc.nil? touch_last_updated_at(lc) self.save end end end |
#touch_last_updated_at! ⇒ Object
60 61 62 63 |
# File 'app/models/lit/source.rb', line 60 def touch_last_updated_at! touch_last_updated_at self.save end |