Class: Ppl::Adapter::Storage::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/ppl/adapter/storage/factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(vcard_adapter) ⇒ Factory

Returns a new instance of Factory.



3
4
5
# File 'lib/ppl/adapter/storage/factory.rb', line 3

def initialize(vcard_adapter)
  @vcard_adapter = vcard_adapter
end

Instance Method Details

#load_adapter(directory) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ppl/adapter/storage/factory.rb', line 7

def load_adapter(directory)
  git_dir = File.join(directory.path, ".git")

  disk_adapter = Ppl::Adapter::Storage::Disk.new(directory)
  disk_adapter.vcard_adapter = @vcard_adapter

  adapter = disk_adapter

  if File.exists?(git_dir)
    git_adapter = Ppl::Adapter::Storage::Git.new(disk_adapter)
    git_adapter.vcard_adapter = @vcard_adapter
    adapter = git_adapter
  end

  return adapter
end