Class: Mamiya::Storages::Filesystem
Instance Attribute Summary
Attributes inherited from Abstract
#application, #config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Abstract
#initialize, #prune
Class Method Details
.find(config = {}) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/mamiya/storages/filesystem.rb', line 8
def self.find(config={})
Hash[Dir[File.join(config[:path], '*')].map do |app_path|
app = File.basename(app_path)
[app, self.new(config.merge(application: app))]
end]
end
|
Instance Method Details
#fetch(package_name, destination) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/mamiya/storages/filesystem.rb', line 38
def fetch(package_name, destination)
package_name = normalize_package_name(package_name)
raise NotFound unless package_exist?(package_name)
package_path = File.join(destination, "#{package_name}.tar.gz")
meta_path = File.join(destination, "#{package_name}.json")
if File.exists?(package_path) && File.exists?(meta_path)
raise AlreadyFetched
end
FileUtils.cp storage_path.join("#{package_name}.tar.gz"), package_path
FileUtils.cp storage_path.join("#{package_name}.json"), meta_path
return Mamiya::Package.new(package_path)
end
|
55
56
57
58
59
60
|
# File 'lib/mamiya/storages/filesystem.rb', line 55
def meta(package_name)
package_name = normalize_package_name(package_name)
return unless package_exist?(package_name)
JSON.parse storage_path.join("#{package_name}.json").read
end
|
#packages ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/mamiya/storages/filesystem.rb', line 15
def packages
storage_path.children(false).group_by { |child|
child.to_s.sub(Package::PATH_SUFFIXES,'')
}.select { |key, files|
files.find { |file| file.to_s.end_with?('.tar.gz') } &&
files.find { |file| file.to_s.end_with?('.json') }
}.keys.sort
end
|
#push(package) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/mamiya/storages/filesystem.rb', line 24
def push(package)
raise TypeError, "package should be a kind of Mamiya::Package" unless package.kind_of?(Mamiya::Package)
raise NotBuilt, "package not built" unless package.exists?
if package_exist?(package.name)
raise AlreadyExists
end
storage_path.mkpath
FileUtils.cp package.path, storage_path.join("#{package.name}.tar.gz")
FileUtils.cp package.meta_path, storage_path.join("#{package.name}.json")
end
|
#remove(package_name) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/mamiya/storages/filesystem.rb', line 62
def remove(package_name)
package_name = normalize_package_name(package_name)
package_path = storage_path.join("#{package_name}.tar.gz")
meta_path = storage_path.join("#{package_name}.json")
if [package_path, meta_path].all? { |_| !_.exist? }
raise Mamiya::Storages::Abstract::NotFound
end
package_path.delete if package_path.exist?
meta_path.delete if meta_path.exist?
end
|