Class: Site

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/models/site.rb

Constant Summary collapse

PREFERENCE_PATHS =
[
  'system:theme_folder_path',
  'system:captcha_path',
  'template:tmpl_file_basepath',
  'member:avatar_path',
  'member:photo_path',
  'member:sig_img_path',
  'member:prv_msg_upload_path'
]

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



20
21
22
# File 'lib/models/site.rb', line 20

def after_initialize
  @preferences = Hash.new
end

#nameObject



24
25
26
# File 'lib/models/site.rb', line 24

def name
  self.site_label
end

#preferencesObject



32
33
34
35
36
37
38
39
# File 'lib/models/site.rb', line 32

def preferences
  if @preferences.empty?
    preference_map.each do |key, method_base|
      @preferences[key] = ExpressionEngine::Preference.new(self.send(method_base.to_sym))
    end
  end
  @preferences
end

#root_pathObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/models/site.rb', line 55

def root_path
  common_elements = nil
  
  PREFERENCE_PATHS.each do |preference|
    group, setting = preference.split(':')
    path = self.preferences[group.to_sym][setting.to_sym].split('/')

    unless path.empty?
      common_elements = path if common_elements.nil?
      common_elements = common_elements & path
    end
  end
  
  common_elements.join('/')
end

#root_path=(other) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/models/site.rb', line 47

def root_path=(other)
  pattern = Regexp.quote(self.root_path)
  PREFERENCE_PATHS.each do |preference|
    group, setting = preference.split(':')
    self.preferences[group.to_sym][setting.to_sym].gsub!(/^#{pattern}/, other)
  end
end

#slugObject



28
29
30
# File 'lib/models/site.rb', line 28

def slug
  self.site_name
end

#update_preferencesObject



41
42
43
44
45
# File 'lib/models/site.rb', line 41

def update_preferences
  preference_map.each do |key, method_base|
    self.send("#{method_base}=".to_sym, @preferences[key].to_s)
  end
end