Class: ForemanTemplates::ParseResult
- Inherits:
-
Object
- Object
- ForemanTemplates::ParseResult
- Defined in:
- app/services/foreman_templates/parse_result.rb
Instance Attribute Summary collapse
-
#additional_errors ⇒ Object
readonly
Returns the value of attribute additional_errors.
-
#additional_info ⇒ Object
readonly
Returns the value of attribute additional_info.
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#imported ⇒ Object
readonly
Returns the value of attribute imported.
-
#name ⇒ Object
Returns the value of attribute name.
-
#template ⇒ Object
Returns the value of attribute template.
-
#template_file ⇒ Object
readonly
Returns the value of attribute template_file.
Instance Method Summary collapse
- #add_exception(exception) ⇒ Object
- #calculate_diff(old, new) ⇒ Object
- #changed? ⇒ Boolean
- #check_for_errors ⇒ Object
- #corrupted_metadata ⇒ Object
- #determine_result_diff ⇒ Object
- #errors ⇒ Object
- #generic_error(additional_msg) ⇒ Object
- #generic_info(additional_msg) ⇒ Object
-
#initialize(template_file) ⇒ ParseResult
constructor
A new instance of ParseResult.
- #matching_filter ⇒ Object
- #missing_model ⇒ Object
- #name_error(exception, template_type) ⇒ Object
- #no_metadata_name ⇒ Object
- #to_h(verbose = false) ⇒ Object
Constructor Details
#initialize(template_file) ⇒ ParseResult
Returns a new instance of ParseResult.
6 7 8 |
# File 'app/services/foreman_templates/parse_result.rb', line 6 def initialize(template_file) @template_file = template_file.split('/').last end |
Instance Attribute Details
#additional_errors ⇒ Object (readonly)
Returns the value of attribute additional_errors.
4 5 6 |
# File 'app/services/foreman_templates/parse_result.rb', line 4 def additional_errors @additional_errors end |
#additional_info ⇒ Object (readonly)
Returns the value of attribute additional_info.
4 5 6 |
# File 'app/services/foreman_templates/parse_result.rb', line 4 def additional_info @additional_info end |
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
4 5 6 |
# File 'app/services/foreman_templates/parse_result.rb', line 4 def diff @diff end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
4 5 6 |
# File 'app/services/foreman_templates/parse_result.rb', line 4 def exception @exception end |
#imported ⇒ Object (readonly)
Returns the value of attribute imported.
4 5 6 |
# File 'app/services/foreman_templates/parse_result.rb', line 4 def imported @imported end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'app/services/foreman_templates/parse_result.rb', line 3 def name @name end |
#template ⇒ Object
Returns the value of attribute template.
3 4 5 |
# File 'app/services/foreman_templates/parse_result.rb', line 3 def template @template end |
#template_file ⇒ Object (readonly)
Returns the value of attribute template_file.
4 5 6 |
# File 'app/services/foreman_templates/parse_result.rb', line 4 def template_file @template_file end |
Instance Method Details
#add_exception(exception) ⇒ Object
63 64 65 66 67 |
# File 'app/services/foreman_templates/parse_result.rb', line 63 def add_exception(exception) @imported = false @exception = exception self end |
#calculate_diff(old, new) ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/services/foreman_templates/parse_result.rb', line 95 def calculate_diff(old, new) if old.present? && new.present? && old != new Diffy::Diff.new(old, new, :include_diff_info => true).to_s(:color) else nil end end |
#changed? ⇒ Boolean
91 92 93 |
# File 'app/services/foreman_templates/parse_result.rb', line 91 def changed? @diff.present? end |
#check_for_errors ⇒ Object
58 59 60 61 |
# File 'app/services/foreman_templates/parse_result.rb', line 58 def check_for_errors @imported = @template.errors.blank? self end |
#corrupted_metadata ⇒ Object
35 36 37 |
# File 'app/services/foreman_templates/parse_result.rb', line 35 def generic_error "Failed to parse metadata" end |
#determine_result_diff ⇒ Object
83 84 85 86 87 88 89 |
# File 'app/services/foreman_templates/parse_result.rb', line 83 def determine_result_diff return if @template.nil? || !@template.template_changed? template_was = @template.template_was template_is = @template.template @diff = calculate_diff(template_was, template_is) end |
#errors ⇒ Object
29 30 31 32 33 |
# File 'app/services/foreman_templates/parse_result.rb', line 29 def errors @template&.errors&.&.transform_values do |v| v.join(', ') end end |
#generic_error(additional_msg) ⇒ Object
51 52 53 54 55 56 |
# File 'app/services/foreman_templates/parse_result.rb', line 51 def generic_error(additional_msg) @imported = false @additional_errors = additional_msg Logging.logger('app').debug "Error in '#{@template_file}': #{additional_msg}" self end |
#generic_info(additional_msg) ⇒ Object
69 70 71 72 73 74 |
# File 'app/services/foreman_templates/parse_result.rb', line 69 def generic_info(additional_msg) @imported = false @additional_info = additional_msg Logging.logger('app').debug "Not importing #{@template_file}: #{additional_msg}" self end |
#matching_filter ⇒ Object
39 40 41 |
# File 'app/services/foreman_templates/parse_result.rb', line 39 def matching_filter generic_info "Skipping, 'name' filtered out based on 'filter' and 'negate' settings" end |
#missing_model ⇒ Object
47 48 49 |
# File 'app/services/foreman_templates/parse_result.rb', line 47 def missing_model generic_error "No 'model' found in metadata" end |
#name_error(exception, template_type) ⇒ Object
76 77 78 79 80 81 |
# File 'app/services/foreman_templates/parse_result.rb', line 76 def name_error(exception, template_type) @imported = false @exception = exception @additional_errors = "Template type #{template_type} was not found, are you missing a plugin?" self end |
#no_metadata_name ⇒ Object
43 44 45 |
# File 'app/services/foreman_templates/parse_result.rb', line 43 def generic_error "No 'name' found in metadata" end |
#to_h(verbose = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/foreman_templates/parse_result.rb', line 10 def to_h(verbose = false) res = { :name => @name, :id => @template.present? ? @template.id : nil, :changed => changed?, :imported => @imported, :additional_errors => @additional_errors, :additional_info => @additional_info, :exception => @exception&., :validation_errors => errors, :file => @template_file, :type => @template.present? ? @template.class.name.underscore : nil } # false comes as a string when using rake tasks res[:diff] = @diff if verbose && verbose != 'false' res end |