Class: SadieStorageManager
- Inherits:
-
Object
- Object
- SadieStorageManager
- Defined in:
- lib/sadie_storage_manager.rb
Instance Method Summary collapse
- #get(key) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize ⇒ SadieStorageManager
constructor
A new instance of SadieStorageManager.
- #mechanism_is_registered?(mechanism_handle) ⇒ Boolean
- #register_storage_mechanism(handle, mechanism) ⇒ Object
- #set(params) ⇒ Object
- #unset(key) ⇒ Object
Constructor Details
#initialize ⇒ SadieStorageManager
Returns a new instance of SadieStorageManager.
3 4 5 6 |
# File 'lib/sadie_storage_manager.rb', line 3 def initialize @mechanisms = {} @known_keys = {} end |
Instance Method Details
#get(key) ⇒ Object
22 23 24 |
# File 'lib/sadie_storage_manager.rb', line 22 def get( key ) @mechanisms[@known_keys[key]].get( key ) if has_key?( key ) end |
#has_key?(key) ⇒ Boolean
18 19 20 |
# File 'lib/sadie_storage_manager.rb', line 18 def has_key?( key ) @known_keys.has_key?( key ) end |
#mechanism_is_registered?(mechanism_handle) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/sadie_storage_manager.rb', line 12 def mechanism_is_registered?( mechanism_handle ) @mechanisms.has_key?( mechanism_handle ) end |
#register_storage_mechanism(handle, mechanism) ⇒ Object
8 9 10 |
# File 'lib/sadie_storage_manager.rb', line 8 def register_storage_mechanism( handle, mechanism ) @mechanisms[handle] = mechanism end |
#set(params) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sadie_storage_manager.rb', line 33 def set( params ) unless params.nil? if params.is_a? Hash if params.has_key?( :mechanism ) if mechanism_is_registered? params[:mechanism] if params.has_key?( :keys ) && params[:keys].is_a?( Array ) && params.has_key?( :value ) params[:keys].each do |key| @mechanisms[params[:mechanism]].set( key, params[:value] ) @known_keys[key] = params[:mechanism] end end end end end end end |
#unset(key) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/sadie_storage_manager.rb', line 26 def unset( key ) if has_key?( key ) @mechanisms[@known_keys[key]].unset( key ) @known_keys.delete key end end |