Skip to content

Commit 9154706

Browse files
committed
Convert to use shared utility method
1 parent c04e0c4 commit 9154706

File tree

1 file changed

+4
-13
lines changed
  • lib/octocatalog-diff/catalog-diff/display

1 file changed

+4
-13
lines changed

lib/octocatalog-diff/catalog-diff/display/text.rb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
22

33
require_relative '../display'
4-
require_relative '../../util/colored.rb'
4+
require_relative '../../util/colored'
5+
require_relative '../../util/util'
56

67
require 'diffy'
78
require 'json'
@@ -447,26 +448,16 @@ def self.class_name_for_diffy(class_name)
447448
class_name
448449
end
449450

450-
# Utility Method!
451-
# `is_a?(class)` only allows one method, but this uses an array
452-
# @param object [?] Object to consider
453-
# @param classes [Array] Classes to determine if object is a member of
454-
# @return [Boolean] True if object is_a any of the classes, false otherwise
455-
def self.object_is_any_of?(object, classes)
456-
classes.each { |clazz| return true if object.is_a? clazz }
457-
false
458-
end
459-
460451
# Utility Method!
461452
# Given an arbitrary object, convert it into a string for use by 'diffy'.
462453
# This basically exists so we can do something prettier than just calling .inspect or .to_s
463454
# on object types we anticipate seeing, while not failing entirely on other object types.
464455
# @param obj [?] Object to be stringified
465456
# @return [String] String representation of object for diffy
466457
def self.stringify_for_diffy(obj)
467-
return JSON.pretty_generate(obj) if object_is_any_of?(obj, [Hash, Array])
458+
return JSON.pretty_generate(obj) if OctocatalogDiff::Util::Util.object_is_any_of?(obj, [Hash, Array])
468459
return '""' if obj.is_a?(String) && obj == ''
469-
return obj if object_is_any_of?(obj, [String, Fixnum, Integer, Float])
460+
return obj if OctocatalogDiff::Util::Util.object_is_any_of?(obj, [String, Fixnum, Integer, Float])
470461
"#{class_name_for_diffy(obj.class)}: #{obj.inspect}"
471462
end
472463

0 commit comments

Comments
 (0)