Class: Cockpit::Store::Database
- Inherits:
-
Base
- Object
- Base
- Cockpit::Store::Database
show all
- Defined in:
- lib/cockpit/store.rb
Instance Attribute Summary
Attributes inherited from Base
#configurable
Instance Method Summary
collapse
Methods inherited from Base
#[]=, #configuration, #get!, #initialize, #set, #set!, #set_one, #tree, #tree=
Instance Method Details
#clear(options = {}) ⇒ Object
70
71
72
73
|
# File 'lib/cockpit/store.rb', line 70
def clear(options = {})
configuration.setting_class.all.collect(&:destroy) if options[:hard] == true
super(options)
end
|
#find_or_create(key) ⇒ Object
75
76
77
78
|
# File 'lib/cockpit/store.rb', line 75
def find_or_create(key)
result = configuration.setting_class.find(key.to_s) rescue nil
result ||= configuration.setting_class.create(:key => key.to_s)
end
|
#get(key) ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/cockpit/store.rb', line 90
def get(key)
result = super(key)
if result.blank? && setting = find_or_create(key)
set(key => setting.value)
result = super(key)
else
end
result
end
|
#set_one_with_database(key, value) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/cockpit/store.rb', line 80
def set_one_with_database(key, value)
setting = find_or_create(key)
cast_as = (setting.cast_as || Cockpit.get_type(value)).to_s
attributes = {:value => value, :cast_as => cast_as}
attributes[:configurable] = self.configurable if self.configurable
setting.update_attributes(attributes)
set_one_without_database(key, Cockpit.type_cast(value, cast_as))
end
|