module Shoulda::Matchers::Util
@private
Public Class Methods
a_or_an(next_word)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 35 def self.a_or_an(next_word) if next_word =~ /\A[aeiou]/i && next_word != 'unique' "an #{next_word}" else "a #{next_word}" end end
deconstantize(path)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 7 def self.deconstantize(path) if defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:deconstantize) ActiveSupport::Inflector.deconstantize(path) else path.to_s[0...(path.to_s.rindex('::') || 0)] end end
dummy_value_for(column_type, array: false)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 76 def self.dummy_value_for(column_type, array: false) if array [dummy_value_for(column_type, array: false)] else case column_type when :integer 0 when :date Date.new(2100, 1, 1) when :datetime, :timestamp DateTime.new(2100, 1, 1) when :time Time.new(2100, 1, 1) when :uuid SecureRandom.uuid when :boolean true else 'dummy value' end end end
indent(string, width)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 29 def self.indent(string, width) return if !string indentation = ' ' * width string.split(/[\n\r]/).map { |line| indentation + line }.join("\n") end
inspect_hash(hash)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 62 def self.inspect_hash(hash) output = '‹{' output << hash.map { |key, value| if key.is_a?(Symbol) "#{key}: #{value.inspect}" else "#{key.inspect} => #{value.inspect}" end }.join(', ') output << '}›' end
inspect_range(range)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 58 def self.inspect_range(range) "#{inspect_value(range.first)} to #{inspect_value(range.last)}" end
inspect_value(value)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 43 def self.inspect_value(value) case value when Hash inspect_hash(value) when Range inspect_range(value) else "‹#{value.inspect}›" end end
inspect_values(values)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 54 def self.inspect_values(values) values.map { |value| inspect_value(value) } end
safe_constantize(camel_cased_word)
click to toggle source
# File lib/shoulda/matchers/util.rb, line 16 def self.safe_constantize(camel_cased_word) if defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:safe_constantize) ActiveSupport::Inflector.safe_constantize(camel_cased_word) else begin camel_cased_word.constantize rescue NameError nil end end end