Class: Radmin::Setting

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](key) ⇒ Object



8
9
10
11
# File 'app/models/radmin/setting.rb', line 8

def [](key)
    	settings = Rails.cache.fetch('Radmin::Settings') { Radmin::Setting.to_hash }
    	settings[key]
end

.[]=(key, value) ⇒ Object



13
14
15
16
17
# File 'app/models/radmin/setting.rb', line 13

def []=(key, value)
	pair = find_or_initialize_by_key(key)
	pair.update_attributes(:value => value)
	value
end

.to_hashObject



19
20
21
# File 'app/models/radmin/setting.rb', line 19

def to_hash
  Hash[ *find(:all).map { |pair| [pair.key, pair.value] }.flatten ]
end

Instance Method Details

#valueObject



28
29
30
31
32
33
34
35
36
# File 'app/models/radmin/setting.rb', line 28

def value
  unless new_record?
    if key.ends_with? "?"
      self[:value] == "true"
    else
      self[:value]
    end
  end
end

#value=(param) ⇒ Object



24
25
26
# File 'app/models/radmin/setting.rb', line 24

def value=(param)
  self[:value] = param.to_s
end