Class: TDiary::IO::MongoDB::Plugin
- Inherits:
-
Object
- Object
- TDiary::IO::MongoDB::Plugin
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/tdiary/io/mongodb.rb
Class Method Summary collapse
- .delete(plugin_name, key) ⇒ Object
- .get(plugin_name, key) ⇒ Object
- .keys(plugin_name) ⇒ Object
- .set(plugin_name, key, value) ⇒ Object
Class Method Details
.delete(plugin_name, key) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/tdiary/io/mongodb.rb', line 97 def self.delete(plugin_name, key) record = where(plugin: plugin_name, key: key).first if record record.delete end end |
.get(plugin_name, key) ⇒ Object
82 83 84 85 |
# File 'lib/tdiary/io/mongodb.rb', line 82 def self.get(plugin_name, key) record = where(plugin: plugin_name, key: key).first return record ? record.value : nil end |
.keys(plugin_name) ⇒ Object
104 105 106 107 |
# File 'lib/tdiary/io/mongodb.rb', line 104 def self.keys(plugin_name) records = where(plugin: plugin_name) return records.map(&:key) rescue [] end |
.set(plugin_name, key, value) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/tdiary/io/mongodb.rb', line 87 def self.set(plugin_name, key, value) record = where(plugin: plugin_name, key: key).first if record record.update_attributes(value: value) else record = self.new(plugin: plugin_name, key: key, value: value) record.save! end end |