Class: SadieStorageManager
- Inherits:
-
Object
- Object
- SadieStorageManager
- Defined in:
- lib/sadie_storage_manager.rb
Instance Method Summary collapse
- #get(key) ⇒ Object
- #has_key?(key) ⇒ Boolean
- #has_metadata?(key) ⇒ Boolean
-
#initialize ⇒ SadieStorageManager
constructor
A new instance of SadieStorageManager.
- #mechanism_is_registered?(mechanism_handle) ⇒ Boolean
- #metadata(key) ⇒ Object
- #register_storage_mechanism(handle, mechanism) ⇒ Object
- #registered_mechanisms ⇒ Object
- #set(params) ⇒ Object
- #unset(key) ⇒ Object
- #where_key?(key) ⇒ Boolean
Constructor Details
#initialize ⇒ SadieStorageManager
Returns a new instance of SadieStorageManager.
3 4 5 |
# File 'lib/sadie_storage_manager.rb', line 3 def initialize @mechanisms = {} end |
Instance Method Details
#get(key) ⇒ Object
34 35 36 |
# File 'lib/sadie_storage_manager.rb', line 34 def get( key ) @mechanisms[where_key?( key )].get( key ) if has_key?( key ) end |
#has_key?(key) ⇒ Boolean
30 31 32 |
# File 'lib/sadie_storage_manager.rb', line 30 def has_key?( key ) ( ! where_key?( key ).nil? ) end |
#has_metadata?(key) ⇒ Boolean
44 45 46 |
# File 'lib/sadie_storage_manager.rb', line 44 def ( key ) @mechanisms[where_key?( key )].( key ) if has_key?( key ) end |
#mechanism_is_registered?(mechanism_handle) ⇒ Boolean
11 12 13 |
# File 'lib/sadie_storage_manager.rb', line 11 def mechanism_is_registered?( mechanism_handle ) @mechanisms.has_key?( mechanism_handle ) end |
#metadata(key) ⇒ Object
48 49 50 |
# File 'lib/sadie_storage_manager.rb', line 48 def ( key ) @mechanisms[where_key?( key )].( key ) if has_key?( key ) end |
#register_storage_mechanism(handle, mechanism) ⇒ Object
7 8 9 |
# File 'lib/sadie_storage_manager.rb', line 7 def register_storage_mechanism( handle, mechanism ) @mechanisms[handle] = mechanism end |
#registered_mechanisms ⇒ Object
15 16 17 |
# File 'lib/sadie_storage_manager.rb', line 15 def registered_mechanisms @mechanisms.keys end |
#set(params) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sadie_storage_manager.rb', line 52 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 ) = false if params.has_key?(:metadata) && params[:metadata].is_a?( Hash ) = true end params[:keys].each do |key| if @mechanisms[params[:mechanism]].set( key, params[:value], :metadata => params[:metadata] ) else @mechanisms[params[:mechanism]].set( key, params[:value] ) end end end end end end end end |
#unset(key) ⇒ Object
38 39 40 41 42 |
# File 'lib/sadie_storage_manager.rb', line 38 def unset( key ) if has_key?( key ) @mechanisms[where_key?( key )].unset( key ) end end |
#where_key?(key) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sadie_storage_manager.rb', line 19 def where_key?( key ) ret = nil registered_mechanisms.each do |mech| if @mechanisms[mech].has_key?( key ) ret = mech break end end ret end |