Class: AndParcel::CatalogSet

Inherits:
Object
  • Object
show all
Defined in:
lib/andparcel/catalog.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ CatalogSet

Returns a new instance of CatalogSet.



18
19
20
# File 'lib/andparcel/catalog.rb', line 18

def initialize(root)
	@root=root
end

Instance Method Details

#add(name, url) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/andparcel/catalog.rb', line 40

def add(name, url)
	roster_hash=roster

	roster_hash[name]={'url'=>url}

	open(roster_file, "w") {|f| f.puts(roster_hash.to_json)}
end

#find(name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/andparcel/catalog.rb', line 60

def find(name)
	roster.each_value do |cat|
		packages=JSON.parse(open(cat['url']) {|f| f.read})
		package=packages['parcels'][name]

		if package
			if (urls=package['url'])
				if urls.kind_of?(Enumerable)
					return(urls.first)
				end
				
				return(urls)
			elsif (path=package['path'])
				uri=URI.parse cat['url']
				
				return(uri+path)
			end
		end
	end
	
	nil
end

#namesObject



56
57
58
# File 'lib/andparcel/catalog.rb', line 56

def names
	roster.keys
end

#remove(name) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/andparcel/catalog.rb', line 48

def remove(name)
	roster_hash=roster

	roster_hash.delete(name)

	open(roster_file, "w") {|f| f.puts(roster_hash.to_json)}
end

#rosterObject



30
31
32
33
34
35
36
37
38
# File 'lib/andparcel/catalog.rb', line 30

def roster
	fn=roster_file
	
	if File.exists?(fn)
		return(JSON.parse(open(fn) {|f| f.read}))
	end
	
	{}
end

#roster_fileObject



26
27
28
# File 'lib/andparcel/catalog.rb', line 26

def roster_file
	File.join(@root, 'catalogs.json')
end

#sizeObject



22
23
24
# File 'lib/andparcel/catalog.rb', line 22

def size
	roster.size
end