Class: Maven::Model::Tag
- Inherits:
-
Object
show all
- Defined in:
- lib/maven/model/utils.rb
Direct Known Subclasses
Activation, Build, Coordinate, DependencyManagement, Developer, Exclusion, Execution, HashTag, License, ListItems, OS, PluginManagement, Profile, Property, Repository, Resource, SourceControl
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args = {}) ⇒ Tag
Returns a new instance of Tag.
69
70
71
72
73
74
|
# File 'lib/maven/model/utils.rb', line 69
def initialize(args = {})
warn "deprecated #{args.inspect}" if args.size > 0
args.each do |k,v|
send("#{k}=".to_sym, v)
end
end
|
Class Method Details
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/maven/model/utils.rb', line 33
def self._tags(prepend, *tags)
if tags.size == 0
@tags
else
tags.each do |tag|
eval <<-EOF
def #{tag.to_s}(val = nil)
@#{tag.to_s} = val if val
@#{tag.to_s}
end
def #{tag.to_s}=(val)
@#{tag.to_s} = val
end
EOF
end
if self.superclass.respond_to?:tags
@tags ||= (self.superclass.tags || []).dup
else
@tags ||= []
end
unless @tags.include? tags[0]
if prepend
@tags.replace([tags, @tags].flatten)
else
@tags.replace([@tags, tags].flatten)
end
end
@tags
end
end
|
25
26
27
|
# File 'lib/maven/model/utils.rb', line 25
def self.prepend_tags(*tags)
_tags(true, *tags)
end
|
29
30
31
|
# File 'lib/maven/model/utils.rb', line 29
def self.tags(*tags)
_tags(false, *tags)
end
|
Instance Method Details
#_name ⇒ Object
65
66
67
|
# File 'lib/maven/model/utils.rb', line 65
def _name
self.class.to_s.downcase.sub(/.*::/, '')
end
|
76
77
78
79
|
# File 'lib/maven/model/utils.rb', line 76
def (c)
@comment = c if c
@comment
end
|
#to_xml(buf = "", indent = "") ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/maven/model/utils.rb', line 81
def to_xml(buf = "", indent = "")
buf << "#{indent}<#{_name}>\n"
buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
self.class.tags.each do |var|
val = instance_variable_get("@#{var}".to_sym)
var = var.to_s.gsub(/_(.)/) { $1.upcase }
case val
when Array
val.flatten!
if val.size > 0
buf << "#{indent} <#{var}>\n"
val.each do |v|
if v.is_a? Tag
v.to_xml(buf, indent + " ")
else
buf << "#{indent} <#{var.to_s.sub(/s$/, '')}>#{v}</#{var.to_s.sub(/s$/, '')}>\n"
end
end
buf << "#{indent} </#{var}>\n"
end
when Hash
if val.size > 0
buf << "#{indent} <#{var}>\n"
val.keys.sort{ |n,m| n.to_s <=> m.to_s }.each do |k|
v = val[k]
if v.is_a? Tag
v.to_xml(buf, indent + " ")
else
buf << "#{indent} <#{k}>#{v}</#{k}>\n"
end
end
buf << "#{indent} </#{var}>\n"
end
when Tag
val.to_xml(buf, indent + " ")
else
buf << "#{indent} <#{var}>#{val}</#{var}>\n" if val
end
end
buf << "#{indent}</#{_name.sub(/ .*$/, '')}>\n"
buf
end
|