Class: ReaPack::Index::Package
Constant Summary
collapse
- TYPE_ATTR =
'type'.freeze
- DESC_ATTR =
'desc'.freeze
- DIR_SEPARATOR =
Regexp.union(
*[File::SEPARATOR, File::ALT_SEPARATOR].compact).freeze
Constants inherited
from NamedNode
NamedNode::NAME_ATTR
Instance Attribute Summary collapse
Attributes inherited from NamedNode
#node
Instance Method Summary
collapse
Methods inherited from NamedNode
#children, create, #empty?, fetch, find_all, find_one, #is_new?, #name, #remove, tag
Constructor Details
#initialize(node) ⇒ Package
Returns a new instance of Package.
14
15
16
17
|
# File 'lib/reapack/index/package.rb', line 14
def initialize(node)
super
@metadata = Metadata.new node
end
|
Instance Attribute Details
Returns the value of attribute metadata.
19
20
21
|
# File 'lib/reapack/index/package.rb', line 19
def metadata
@metadata
end
|
Instance Method Details
#category ⇒ Object
25
26
27
|
# File 'lib/reapack/index/package.rb', line 25
def category
@node.parent[NAME_ATTR]
end
|
#description ⇒ Object
50
51
52
|
# File 'lib/reapack/index/package.rb', line 50
def description
@node[DESC_ATTR].to_s
end
|
#description=(new_desc) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/reapack/index/package.rb', line 54
def description=(new_desc)
new_desc ||= String.new
return if description == new_desc
if new_desc.empty?
@node.remove_attribute DESC_ATTR
else
@node[DESC_ATTR] = new_desc
end
@dirty = true
end
|
#has_version?(name) ⇒ Boolean
68
69
70
71
|
# File 'lib/reapack/index/package.rb', line 68
def has_version?(name)
read_versions
@versions.has_key? name
end
|
#modified? ⇒ Boolean
21
22
23
|
# File 'lib/reapack/index/package.rb', line 21
def modified?
super || versions.any? {|ver| ver.modified? } || @metadata.modified?
end
|
#path ⇒ Object
33
34
35
|
# File 'lib/reapack/index/package.rb', line 33
def path
@path ||= File.join category, name if category && name
end
|
#topdir ⇒ Object
29
30
31
|
# File 'lib/reapack/index/package.rb', line 29
def topdir
category&.split(DIR_SEPARATOR)&.first
end
|
#type ⇒ Object
37
38
39
|
# File 'lib/reapack/index/package.rb', line 37
def type
@node[TYPE_ATTR]&.to_sym
end
|
#type=(new_type) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/reapack/index/package.rb', line 41
def type=(new_type)
new_type = new_type.to_sym
return if type == new_type
@node[TYPE_ATTR] = new_type
@dirty = true
end
|
#version(name) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/reapack/index/package.rb', line 78
def version(name)
if has_version? name
ver = @versions[name]
else
@versions.each_key {|other|
normalized = [other, name].map {|ver|
ver.scan(/(\d+)|([a-zA-Z]+)/).map {|match|
match.first ? match.first.to_i : match.last
}.join '.'
}
if normalized.uniq.size < 2
raise Error, "version #{name} is a duplicate of version #{other}"
end
}
ver = @versions[name] = Version.create name, @node
end
if block_given?
yield ver
else
ver
end
end
|
#versions ⇒ Object
73
74
75
76
|
# File 'lib/reapack/index/package.rb', line 73
def versions
read_versions
@versions.values
end
|