Class: Readiness::Repos::UserFields
- Defined in:
- lib/support_readiness/repos/user_fields.rb
Overview
Defines the class UserFields within the module Readiness::Repos.
Class Method Summary collapse
-
.compare(zendesk_client, location = 'data', verbose = false) ⇒ Hash
Compares the repo user fields files to the Zendesk instance user fields.
-
.detailed_diff(repo, zendesk) ⇒ Object
Outputs a comparison report.
-
.gather(client, location = 'data') ⇒ Array
Parses repo user field files.
-
.repo_check(objects) ⇒ Object
Performs basic checks on the repo.
-
.report_diffs ⇒ Object
Outputs a comparison report.
-
.report_errors ⇒ Object
Outputs an error report and exits with a status code of 1.
-
.update_object(repo, zendesk) ⇒ Object
Creates an instance of Zendesk::UserFields to use for updates.
-
.validity_check(file, object) ⇒ Object
Performs basic checks on a repo file.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.compare(zendesk_client, location = 'data', verbose = false) ⇒ Hash
Compares the repo user fields files to the Zendesk instance user fields
22 23 24 25 26 27 28 29 30 31 32 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 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/support_readiness/repos/user_fields.rb', line 22 def self.compare(zendesk_client, location = 'data', verbose = false) @from_repo = gather(zendesk_client, location) @from_zendesk = Zendesk::UserFields.list(zendesk_client) @diffs = { field_updates: [], field_creates: [], option_updates: [], option_deletes: [] } @from_repo.each do |repo| zd = @from_zendesk.detect { |z| z.title == repo.title } if zd.nil? pp @from_zendesk pp repo @diffs[:field_creates].push(repo) unless repo..nil? repo..each do |o| @diffs[:option_updates].push({ "#{repo.title}" => o }) end end else comparable_zd = zd.dup comparable_repo = repo.dup comparable_zd.id = nil comparable_zd. = nil comparable_repo. = nil @diffs[:field_updates].push(update_object(repo, zd)) if to_clean_json(comparable_zd) != to_clean_json(comparable_repo) detailed_diff(comparable_repo, comparable_zd) if verbose && to_clean_json(comparable_repo) != to_clean_json(comparable_zd) next if repo..nil? = @from_zendesk.detect { |z| z.title == repo.title }. repo..map! { |o| Zendesk::UserFieldOptions.new(o) } unless repo..first.is_a? Object repo..each do |repo_option| repo_option.position = repo..index(repo_option) if repo_option.position.nil? repo_option.id = nil zd_option = .detect { |zd_o| zd_o.value == repo_option.value } zd_option.id = nil unless zd_option.nil? if zd_option.nil? || to_clean_json(zd_option) != to_clean_json(repo_option) @diffs[:option_updates].push({ "#{repo.title}" => repo_option }) end end .each do |zd_option| repo_option = repo..detect { |rp_o| rp_o.value == zd_option.value } if repo_option.nil? @diffs[:option_deletes].push({ "#{repo.title}" => zd_option }) end end end end report_diffs if verbose @diffs end |
.detailed_diff(repo, zendesk) ⇒ Object
Outputs a comparison report
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/support_readiness/repos/user_fields.rb', line 95 def self.detailed_diff(repo, zendesk) puts "Detailed diff of #{repo.title}" repo.instance_variables.each do |v| next if v == :@id if repo.instance_variable_get(v) != zendesk.instance_variable_get(v) puts "- #{v} Repo:" pp repo.instance_variable_get(v) puts " #{v} Zendesk:" pp zendesk.instance_variable_get(v) end end end |
.gather(client, location = 'data') ⇒ Array
Parses repo user field files
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/support_readiness/repos/user_fields.rb', line 141 def self.gather(client, location = 'data') @errors = [] @location = location array = [] Dir["#{@location}/**/*.yaml"].each do |f| object = YAML.safe_load_file(f) validity_check(f, object) object['id'] = nil object['title_in_portal'] = (object['visible_in_portal'] ? object['title_in_portal'] : object['title']) array.push(Zendesk::UserFields.new(client, object)) end repo_check(array) report_errors unless @errors.count.zero? array end |
.repo_check(objects) ⇒ Object
Performs basic checks on the repo
193 194 195 196 197 198 199 200 |
# File 'lib/support_readiness/repos/user_fields.rb', line 193 def self.repo_check(objects) duplicate_names = objects.group_by { |o| o.title }.select { |k, v| v.size > 1 }.map(&:first) unless duplicate_names.count.zero? duplicate_names.each do |d| @errors.push("The title '#{d}' is used in multiple files") end end end |
.report_diffs ⇒ Object
Outputs a comparison report
80 81 82 83 84 85 86 |
# File 'lib/support_readiness/repos/user_fields.rb', line 80 def self.report_diffs puts 'Compare report:' puts "- Field Creates: #{@diffs[:field_creates].count}" puts "- Field Updates: #{@diffs[:field_updates].count}" puts "- Option Updates: #{@diffs[:option_updates].count}" puts "- Option Deletes: #{@diffs[:option_deletes].count}" end |
.report_errors ⇒ Object
Outputs an error report and exits with a status code of 1
162 163 164 165 166 167 168 169 |
# File 'lib/support_readiness/repos/user_fields.rb', line 162 def self.report_errors puts 'The following errors were found in the repo files:' @errors.each do |e| puts "- #{e}" end puts 'Rectify the errors and retry. We cannot proceed with those errors occurring.' exit 1 end |
.update_object(repo, zendesk) ⇒ Object
Creates an instance of Zendesk::UserFields to use for updates
117 118 119 120 121 |
# File 'lib/support_readiness/repos/user_fields.rb', line 117 def self.update_object(repo, zendesk) object = repo object.id = zendesk.id object end |
.validity_check(file, object) ⇒ Object
Performs basic checks on a repo file
178 179 180 181 182 183 184 185 |
# File 'lib/support_readiness/repos/user_fields.rb', line 178 def self.validity_check(file, object) folder = file.split("#{@location}/").last.split('/').first @errors.push("Missing type: #{file}") if object['type'].nil? @errors.push("Missing title: #{file}") if object['title'].nil? @errors.push("Missing position: #{file}") if object['position'].nil? @errors.push("Inactive user field in active folder: #{file}") if folder == 'active' && !object['active'] @errors.push("Active user field in inactive folder: #{file}") if folder == 'inactive' && object['active'] end |