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
61 62 63 64 65 |
# File 'app/services/foreman_templates/parse_result.rb', line 61 def add_exception(exception) @imported = false @exception = exception self end |
#calculate_diff(old, new) ⇒ Object
93 94 95 96 97 98 99 |
# File 'app/services/foreman_templates/parse_result.rb', line 93 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
89 90 91 |
# File 'app/services/foreman_templates/parse_result.rb', line 89 def changed? @diff.present? end |
#check_for_errors ⇒ Object
56 57 58 59 |
# File 'app/services/foreman_templates/parse_result.rb', line 56 def check_for_errors @imported = @template.errors.blank? self end |
#corrupted_metadata ⇒ Object
33 34 35 |
# File 'app/services/foreman_templates/parse_result.rb', line 33 def generic_error "Failed to parse metadata" end |
#determine_result_diff ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/services/foreman_templates/parse_result.rb', line 81 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 |
# File 'app/services/foreman_templates/parse_result.rb', line 29 def errors @template&.errors end |
#generic_error(additional_msg) ⇒ Object
49 50 51 52 53 54 |
# File 'app/services/foreman_templates/parse_result.rb', line 49 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
67 68 69 70 71 72 |
# File 'app/services/foreman_templates/parse_result.rb', line 67 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
37 38 39 |
# File 'app/services/foreman_templates/parse_result.rb', line 37 def matching_filter generic_info "Skipping, 'name' filtered out based on 'filter' and 'negate' settings" end |
#missing_model ⇒ Object
45 46 47 |
# File 'app/services/foreman_templates/parse_result.rb', line 45 def missing_model generic_error "No 'model' found in metadata" end |
#name_error(exception, template_type) ⇒ Object
74 75 76 77 78 79 |
# File 'app/services/foreman_templates/parse_result.rb', line 74 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
41 42 43 |
# File 'app/services/foreman_templates/parse_result.rb', line 41 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 => transformed_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 |