Class: Property

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

Direct Known Subclasses

Amavis, Awstats, Dovecot, Dspam, Nginx, Postfix, Spamassassin

Defined Under Namespace

Classes: Amavis, Awstats, Dovecot, Dspam, Nginx, Postfix, Spamassassin

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'app/models/property.rb', line 5

def collection
  @collection
end

#multipleObject (readonly)

Returns the value of attribute multiple.



5
6
7
# File 'app/models/property.rb', line 5

def multiple
  @multiple
end

#translateObject (readonly)

Returns the value of attribute translate.



5
6
7
# File 'app/models/property.rb', line 5

def translate
  @translate
end

Class Method Details

.add(service, key, value, template) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/property.rb', line 14

def self.add(service, key, value, template)
  p = Property.find_by_key(key)||Property.new
  p.key = key; p.value = value; p.template = template
  case service
    when :postfix
      p.service = POSTFIX
    when :dovecot
      p.service = DOVECOT
    when :awstats
      p.service = AWSTATS
    when :dspam
      p.service = DSPAM
    when :nginx
      p.service = NGINX
    when :amavis
      p.service = AMAVIS
    when :spamassassin
      p.service = SPAMASSASSIN
    else
      p.service = APPLICATION
  end
  p.save
end

.all_new_valuesObject



38
39
40
# File 'app/models/property.rb', line 38

def self.all_new_values
  self.select([:key, :value, :new_value]).where 'new_value is not null'
end

.all_new_values_for_writeObject



42
43
44
45
46
# File 'app/models/property.rb', line 42

def self.all_new_values_for_write
  properties = self.where 'new_value is not null'
  # template = "template+type", so remove '+type'
  properties.map {|p| p.template.sub!(/\+.*/, ''); p }
end

.all_to_showObject



48
49
50
51
52
# File 'app/models/property.rb', line 48

def self.all_to_show
  properties = self.select [:id, :key, :value, :new_value, :template]
  # template = "template+type", so remove 'template+'
  properties.map {|p| p.template.sub!(/.*\+/, ''); p }
end

.serviceObject



12
# File 'app/models/property.rb', line 12

def self.service; APPLICATION ;end

Instance Method Details

#has_new_value?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/property.rb', line 89

def has_new_value?
  !self.new_value.nil?
end

#input_typeObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/property.rb', line 54

def input_type
  t = template.to_sym
  if :yes_no ==  t
    @collection = [ 'yes', 'no' ]
    @translate = true
    return :radio_buttons

  elsif :on_off == t
    @collection = [ 'on', 'off']
    @translate = true
    return :radio_buttons

  elsif [:select_from_enum, :select_from_list].include? t
    arr = self.value.split(';')
    @collection = arr.map {|s| s.sub('+','') }
    @translate = t == :select_from_enum
    self.value = arr.select {|s| s.first == '+' }.first[1..-1]
    return :select

  elsif [:multiselect_from_enum, :multiselect_from_list].include? t
    arr = self.value.split(';')
    @collection = arr.map {|s| s.sub('+','') }
    @multiple = true
    @translate = t == :multiselect_from_enum
    self.value = arr.map {|s| s[1..-1] if s.first == '+' }.compact
    return :select

  elsif [:integer, :select].include? t
    return t

  else
    return :string
  end
end

#set_value(value) ⇒ Object



93
94
95
# File 'app/models/property.rb', line 93

def set_value(value)
  self.update_attribute :new_value, value
end