Module: BrowsingHistory::Storage::ConfigureMethods

Defined in:
lib/browsing_history/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_storage_typeObject (readonly)

Returns the value of attribute current_storage_type.



13
14
15
# File 'lib/browsing_history/storage.rb', line 13

def current_storage_type
  @current_storage_type
end

Instance Method Details

#attach_storage(storage_type, **opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/browsing_history/storage.rb', line 23

def attach_storage(storage_type, **opts)
  storage = storages[storage_type]

  if storage
    storage.connect(opts)
    @current_storage_type = storage_type
  else
    raise InvalidStorage
  end
end

#current_storageObject



15
16
17
# File 'lib/browsing_history/storage.rb', line 15

def current_storage
  storages[current_storage_type]
end

#init_storagesObject

Raises:



34
35
36
37
38
39
40
41
42
# File 'lib/browsing_history/storage.rb', line 34

def init_storages
  BrowsingHistory.storage_types.each do |key|
    storages[key] =
      "BrowsingHistory::Storages::#{key.to_s.camelize}".constantize
  end

  raise StoragesNotSet if storages.empty?
  attach_storage(storages.keys.first)
end

#storagesObject



19
20
21
# File 'lib/browsing_history/storage.rb', line 19

def storages
  @storages ||= {}
end