Class: FC::Var
- Inherits:
-
Object
- Object
- FC::Var
- Defined in:
- lib/fc/var.rb
Class Attribute Summary collapse
-
.cache_time ⇒ Object
Returns the value of attribute cache_time.
Class Method Summary collapse
Class Attribute Details
.cache_time ⇒ Object
Returns the value of attribute cache_time.
6 7 8 |
# File 'lib/fc/var.rb', line 6 def cache_time @cache_time end |
Class Method Details
.get(name, default_value = nil) ⇒ Object
18 19 20 |
# File 'lib/fc/var.rb', line 18 def self.get(name, default_value = nil) get_all[name] || default_value end |
.get_all ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fc/var.rb', line 22 def self.get_all if !@get_all_read_time || Time.new.to_i - @get_all_read_time > cache_time @all_vars = {} FC::DB.query("SELECT * FROM #{FC::DB.prefix}vars").each do |row| @all_vars[row['name']] = row['val'] @all_vars[row['name'].to_sym] = row['val'] end @get_all_read_time = Time.new.to_i end @all_vars end |
.set(name, val) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/fc/var.rb', line 11 def self.set(name, val) FC::DB.query("UPDATE #{FC::DB.prefix}vars SET val='#{Mysql2::Client.escape(val.to_s)}' WHERE name='#{Mysql2::Client.escape(name.to_s)}'") FC::DB.query("INSERT IGNORE INTO #{FC::DB.prefix}vars SET val='#{Mysql2::Client.escape(val.to_s)}', name='#{Mysql2::Client.escape(name.to_s)}'") @all_vars[name.to_s] = val.to_s @all_vars[name.to_sym] = val.to_s end |