orbit-basic/app/models/site.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

class Site
2012-05-06 16:54:18 +00:00
METAS = ['description', 'keywords']
include Mongoid::Document
2011-03-08 09:25:46 +00:00
include Mongoid::Timestamps
field :in_use_locales, :type => Array
field :valid_locales, :type => Array
2011-08-18 05:43:33 +00:00
field :roaming_id
field :private_key, :type => Binary
field :public_key, :type => Binary
field :title_always_on, :type => Boolean, :default => false
2012-05-09 03:38:29 +00:00
field :mail_settings, :type => Hash
2011-08-18 05:43:33 +00:00
field :school
field :department
field :title, localize: true
field :footer, localize: true
field :sub_menu, localize: true
2011-08-18 05:43:33 +00:00
has_many :site_metas, :autosave => true, :dependent => :destroy
2012-05-06 16:54:18 +00:00
2011-08-18 05:43:33 +00:00
def generate_keys
private_key = OpenSSL::PKey::RSA.generate(2048)
self.public_key = private_key.public_key.to_s
self.private_key = private_key.to_s
end
def registered?
!self.roaming_id.blank?
end
2011-08-23 11:40:49 +00:00
def up_to_date?
2011-08-25 00:30:09 +00:00
res = res.split('rails_3_1').pop.gsub('(', '').gsub(')','').strip rescue nil
2011-08-23 11:40:49 +00:00
res.eql?('local out of date') ? false : true
end
2012-05-06 16:54:18 +00:00
METAS.each do |meta|
2012-07-26 05:27:27 +00:00
define_method meta do |locale|
2012-05-06 16:54:18 +00:00
fetch_meta = self.site_metas.where(key: meta).limit(1)
2012-07-26 05:27:27 +00:00
fetch_meta.blank? ? nil : fetch_meta[0].title_translations[locale]
2012-05-06 16:54:18 +00:00
end
define_method "#{meta}=" do |values|
2012-07-26 05:27:27 +00:00
fetch_meta = self.site_metas.where(key: meta).limit(1)[0] rescue nil
fetch_meta = self.site_metas.build(key: meta) if fetch_meta.blank?
fetch_meta.title_translations = values
fetch_meta.save
2012-05-06 16:54:18 +00:00
end
end
2011-08-23 11:40:49 +00:00
end