Class: PuppetGenerator::Models::ErrorMessage

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet_generator/models/error_message.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, all, all_names_as_string, clear, create, delete, #enable, enable, #enabled?, #eql?, find, find_all, inherited, #name?, register

Constructor Details

#initialize(name, code, template) ⇒ ErrorMessage

Returns a new instance of ErrorMessage.



37
38
39
40
41
42
# File 'lib/puppet_generator/models/error_message.rb', line 37

def initialize(name, code, template)
  super(name)

  @code = code
  @template = template
end

Class Attribute Details

.postscriptObject

Returns the value of attribute postscript.



7
8
9
# File 'lib/puppet_generator/models/error_message.rb', line 7

def postscript
  @postscript
end

.preambelObject

Returns the value of attribute preambel.



7
8
9
# File 'lib/puppet_generator/models/error_message.rb', line 7

def preambel
  @preambel
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/puppet_generator/models/error_message.rb', line 5

def code
  @code
end

#postscriptObject

Returns the value of attribute postscript.



5
6
7
# File 'lib/puppet_generator/models/error_message.rb', line 5

def postscript
  @postscript
end

#preambelObject

Returns the value of attribute preambel.



5
6
7
# File 'lib/puppet_generator/models/error_message.rb', line 5

def preambel
  @preambel
end

Class Method Details

.initObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet_generator/models/error_message.rb', line 16

def init
  Models::ErrorMessage.preambel = "Sorry, but I can't fullfill your request. "
  Models::ErrorMessage.postscript = "\n\n=================\nPlease read the manual on \"http://github.com/maxmeyer/puppet_generator\" for more information on how to use the script."

  Models::ErrorMessage.create :invalid_source,         1, "You entered an invalid source \"<%= @source %>\": it's not possible to use this source with \"<%= @command %>."
  Models::ErrorMessage.create :invalid_output_channel, 2, "You entered an invalid output channel: file or directory can be used."
  Models::ErrorMessage.create :empty_source,           3, "The source \"<%= @source %>\" you tell me to use does not contain any entries. Giving up."
  Models::ErrorMessage.create :unknown_import_filter,  4, "There's no import filter \"<%= @requested_import_filter %>\". Available import filters: <%= @available_import_filter %>."
  Models::ErrorMessage.create :invalid_yaml_input,     5, "The input is no YAML valid for this use case."
  Models::ErrorMessage.create :invalid_passwd_input,   6, "The input is no passwd file valid for this use case."
  Models::ErrorMessage.create :unknown_action,         7, "There's no action \"<%= @requested_actions %>\". Available actions: <%= @available_actions %>."
  Models::ErrorMessage.create :filesystem_error,       8, "The file/directory \"<%= @fs_object %>\" does not exist."
  Models::ErrorMessage.create :wrong_template_chosen,  9, "I was not able to find a suitable template for the given command \"<%= @command %>\", for the given tags \"<%= @tags %>\" and for the given destination \"<%= @destination %>\"."
  Models::ErrorMessage.create :interrupt,  98, "You pressed \"CTRL-C\". Exiting."

  m = Models::ErrorMessage.create :internal_error,         99, "Sorry, an internal error occured. This should not happen. Please send a bug report to the author and add the following output to that report:\n\n<%= @exception_message %>"
  m.postscript = "\n\n=================\nPlease go to \"http://github.com/maxmeyer/puppet_generator\" to open the bug report. Thank you very much."

end

.resetObject



9
10
11
12
13
14
# File 'lib/puppet_generator/models/error_message.rb', line 9

def reset
  self.clear

  self.preambel = nil
  self.postscript = nil
end

Instance Method Details

#text(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/puppet_generator/models/error_message.rb', line 44

def text(options={})
  result = []
  result << ( preambel ? preambel : self.class.preambel )
  result << Erubis::Eruby.new(@template).evaluate(options)
  result << ( postscript ? postscript : self.class.postscript )

  result.join
end