Class: Sunstore::Store
- Inherits:
-
Object
- Object
- Sunstore::Store
- Defined in:
- lib/sunstore/store.rb
Constant Summary collapse
- @@instance =
nil
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#store_file ⇒ Object
readonly
Returns the value of attribute store_file.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #config(params = {}) ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #keys ⇒ Object
- #put(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
17 18 19 |
# File 'lib/sunstore/store.rb', line 17 def initialize config end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
7 8 9 |
# File 'lib/sunstore/store.rb', line 7 def basename @basename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/sunstore/store.rb', line 7 def format @format end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
7 8 9 |
# File 'lib/sunstore/store.rb', line 7 def handler @handler end |
#store_file ⇒ Object (readonly)
Returns the value of attribute store_file.
7 8 9 |
# File 'lib/sunstore/store.rb', line 7 def store_file @store_file end |
Class Method Details
.instance ⇒ Object
9 10 11 |
# File 'lib/sunstore/store.rb', line 9 def self.instance @@instance ||= new end |
.reset ⇒ Object
13 14 15 |
# File 'lib/sunstore/store.rb', line 13 def self.reset @@instance = nil end |
Instance Method Details
#clear ⇒ Object
48 49 50 51 |
# File 'lib/sunstore/store.rb', line 48 def clear data.clear save_data end |
#config(params = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/sunstore/store.rb', line 21 def config(params={}) @format = [:yaml,:json,nil].include?(params[:format]) ? params[:format] || :yaml : raise("Only yaml and json currently supported") @basename = params[:basename] || "sunstore" @basedir = params[:basedir] || (defined?(Rails) ? Rails.root.to_s : Dir.getwd) create_dir_structure(@basedir) @handler = Sunstore::Handler.for(format) @store_file = File.join(@basedir,"#{@basename}.#{@handler.type}") end |
#delete(key) ⇒ Object
39 40 41 42 |
# File 'lib/sunstore/store.rb', line 39 def delete(key) data.delete(key) save_data end |
#get(key) ⇒ Object
30 31 32 |
# File 'lib/sunstore/store.rb', line 30 def get(key) data[key] end |
#keys ⇒ Object
44 45 46 |
# File 'lib/sunstore/store.rb', line 44 def keys data.keys end |
#put(key, value) ⇒ Object
34 35 36 37 |
# File 'lib/sunstore/store.rb', line 34 def put(key,value) data[key] = value save_data end |