Module: Shard::ShardDirectory

Included in:
Loader, Saver
Defined in:
lib/shard/shard_directory.rb

Instance Method Summary collapse

Instance Method Details

#create_shard_dir(ref) ⇒ Object

# Module Methods #

#


11
12
13
14
15
16
17
# File 'lib/shard/shard_directory.rb', line 11

def create_shard_dir(ref)
  dir = directory(ref)

  unless shard_dir_exists?(ref)
    FileUtils.mkpath(dir)
  end
end

#directory(ref) ⇒ Object



23
24
25
# File 'lib/shard/shard_directory.rb', line 23

def directory(ref)
  File.join(root_path, ref.user, ref.name, ref.version)
end

#file_path(ref, filename, options = {}) ⇒ Object



31
32
33
# File 'lib/shard/shard_directory.rb', line 31

def file_path(ref, filename, options = {})
  File.join( directory(ref), filename )
end

#find_file_path(ref, filename, options = {}) ⇒ Object



35
36
37
# File 'lib/shard/shard_directory.rb', line 35

def find_file_path(ref, filename, options = {})
  find_file_paths(ref, filename).first
end

#find_file_paths(ref, *filenames) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/shard/shard_directory.rb', line 39

def find_file_paths(ref, *filenames)
  full_names = filenames.map do |filename|
    File.join( directory(ref), filename)
  end

  Dir[ *full_names ]
end

#root_pathObject



27
28
29
# File 'lib/shard/shard_directory.rb', line 27

def root_path
  File.join(Dir.home, '.shard')
end

#shard_dir_exists?(ref) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/shard/shard_directory.rb', line 19

def shard_dir_exists?(ref)
  Dir.exists? directory(ref)
end