Module: Puppet::Interface::FullDocs

Extended by:
DocGen
Includes:
TinyDocs
Included in:
Puppet::Interface, Action
Defined in:
lib/vendor/puppet/interface/documentation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DocGen

attr_doc, strip_whitespace

Methods included from TinyDocs

#build_synopsis

Instance Attribute Details

Returns the value of attribute copyright_owner.



157
158
159
# File 'lib/vendor/puppet/interface/documentation.rb', line 157

def copyright_owner
  @copyright_owner
end

Returns the value of attribute copyright_years.



168
169
170
# File 'lib/vendor/puppet/interface/documentation.rb', line 168

def copyright_years
  @copyright_years
end

Instance Method Details

#author(value = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/vendor/puppet/interface/documentation.rb', line 119

def author(value = nil)
  unless value.nil? then
    unless value.is_a? String
      raise ArgumentError, 'author must be a string; use multiple statements for multiple authors'
    end

    if value =~ /\n/ then
      raise ArgumentError, 'author should be a single line; use multiple statements for multiple authors'
    end
    @authors.push(Puppet::Interface::DocGen.strip_whitespace(value))
  end
  @authors.empty? ? nil : @authors.join("\n")
end

#author=(value) ⇒ Object Also known as: authors=



135
136
137
138
139
140
# File 'lib/vendor/puppet/interface/documentation.rb', line 135

def author=(value)
  if Array(value).any? {|x| x =~ /\n/ } then
    raise ArgumentError, 'author should be a single line; use multiple statements'
  end
  @authors = Array(value).map{|x| Puppet::Interface::DocGen.strip_whitespace(x) }
end

#authorsObject



132
133
134
# File 'lib/vendor/puppet/interface/documentation.rb', line 132

def authors
  @authors
end


143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vendor/puppet/interface/documentation.rb', line 143

def copyright(owner = nil, years = nil)
  if years.nil? and not owner.nil? then
    raise ArgumentError, 'copyright takes the owners names, then the years covered'
  end
  self.copyright_owner = owner unless owner.nil?
  self.copyright_years = years unless years.nil?

  if self.copyright_years or self.copyright_owner then
    "Copyright #{self.copyright_years} by #{self.copyright_owner}"
  else
    "Unknown copyright owner and years."
  end
end


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/vendor/puppet/interface/documentation.rb', line 183

def munge_copyright_year(input)
  case input
  when Range then input
  when Integer then
    if input < 1970 then
      fault = "before 1970"
    elsif input > (future = Time.now.year + 2) then
      fault = "after #{future}"
    end
    if fault then
      raise ArgumentError, "copyright with a year #{fault} is very strange; did you accidentally add or subtract two years?"
    end

    input

  when String then
    input.strip.split(/,/).map do |part|
      part = part.strip
      if part =~ /^\d+$/ then
        part.to_i
      elsif found = part.split(/-/) then
        unless found.length == 2 and found.all? {|x| x.strip =~ /^\d+$/ }
          raise ArgumentError, "#{part.inspect} is not a good copyright year or range"
        end
        Range.new(found[0].to_i, found[1].to_i)
      else
        raise ArgumentError, "#{part.inspect} is not a good copyright year or range"
      end
    end

  when Array then
    result = []
    input.each do |item|
      item = munge_copyright_year item
      if item.is_a? Array
        result.concat item
      else
        result << item
      end
    end
    result

  else
    raise ArgumentError, "#{input.inspect} is not a good copyright year, set, or range"
  end
end

#short_description(value = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/vendor/puppet/interface/documentation.rb', line 106

def short_description(value = nil)
  self.short_description = value unless value.nil?
  if @short_description.nil? then
    return nil if @description.nil?
    lines = @description.split("\n")
    first_paragraph_break = lines.index('') || 5
    grab  = [5, first_paragraph_break].min
    @short_description = lines[0, grab].join("\n")
    @short_description += ' [...]' if (grab < lines.length and first_paragraph_break >= 5)
  end
  @short_description
end