virtual_community.rb
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
class VirtualCommunity < ActiveRecord::Base
# TODO: these are test features
EXISTING_FEATURES = {
'feature1' => _('Enable Feature 1'),
'feature2' => _('Enable Feature 2'),
'feature3' => _('Enable Feature 3'),
}
# #################################################
# Relationships and applied behaviour
# #################################################
# One VirtualCommunity can be reached by many domains
has_many :domains, :as => :owner
# a VirtualCommunity can be configured
acts_as_configurable
# #################################################
# Attributes
# #################################################
# Enables a feature
def enable(feature)
self.settings["#{feature}_enabled"] = true
end
# Disables a feature
def disable(feature)
self.settings["#{feature}_enabled"] = false
end
# Tells if a feature is enabled
def enabled?(feature)
self.settings["#{feature}_enabled"] == true
end
# #################################################
# Validations
# #################################################
# <tt>name</tt> is mandatory
validates_presence_of :name
# only one virtual community can be the default one
validates_uniqueness_of :is_default, :if => (lambda do |virtual_community| virtual_community.is_default? end), :message => _('Only one Virtual Community can be the default one')
# #################################################
# Business logic in general
# #################################################
# the default VirtualCommunity.
def self.default
self.find(:first, :conditions => [ 'is_default = ?', true ] )
end
end