Class: Tr8n::TranslationSource

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tr8n/translation_source.rb

Overview

– Copyright © 2010-2012 Michael Berkovich, tr8n.net

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++

– Tr8n::TranslationSource Schema Information

Table name: tr8n_translation_sources

id                       INTEGER         not null, primary key
source                   varchar(255)    
translation_domain_id    integer         
created_at               datetime        
updated_at               datetime

Indexes

tr8n_sources_source    (source)

++

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache_key(source) ⇒ Object



58
59
60
# File 'app/models/tr8n/translation_source.rb', line 58

def self.cache_key(source)
  "translation_source_#{source}"
end

.find_or_create(source, url = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'app/models/tr8n/translation_source.rb', line 66

def self.find_or_create(source, url = nil)
  Tr8n::Cache.fetch(cache_key(source)) do 
    translation_domain = Tr8n::TranslationDomain.find_or_create(url)
    translation_source = where("source = ? and translation_domain_id = ?", source, translation_domain.id).first
    translation_source ||= create(:source => source, :translation_domain => translation_domain)
    translation_source.update_attributes(:translation_domain => translation_domain) unless translation_source.translation_domain
    translation_source
  end  
end

Instance Method Details

#cache_keyObject



62
63
64
# File 'app/models/tr8n/translation_source.rb', line 62

def cache_key
  self.class.cache_key(source)
end

#clear_cacheObject



76
77
78
# File 'app/models/tr8n/translation_source.rb', line 76

def clear_cache
  Tr8n::Cache.delete(cache_key)
end