Module: Insta::SnapshotName
- Defined in:
- lib/insta/snapshot_name.rb,
sig/insta/snapshot_name.rbs
Class Method Summary collapse
-
.derive(test_name, counter: 1, options: {}) ⇒ String
: (String, ?counter: Integer, ?options: Hash[Symbol, untyped]) -> String.
-
.sanitize(name) ⇒ String
: (String) -> String.
-
.strip_test_prefix(name) ⇒ String
: (String) -> String.
-
.underscore(string) ⇒ String
: (String) -> String.
Class Method Details
.derive(test_name, counter: 1, options: {}) ⇒ String
: (String, ?counter: Integer, ?options: Hash[Symbol, untyped]) -> String
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/insta/snapshot_name.rb', line 38 def self.derive(test_name, counter: 1, options: {}) stripped = strip_test_prefix(test_name) clean_name = sanitize(stripped) suffix = counter > 1 ? "-#{counter}" : "" if && !.empty? = Digest::MD5.hexdigest(.inspect) "#{clean_name}#{suffix}-#{}" else "#{clean_name}#{suffix}" end end |
.sanitize(name) ⇒ String
: (String) -> String
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/insta/snapshot_name.rb', line 8 def self.sanitize(name) sanitizer = Insta.configuration.snapshot_sanitizer if sanitizer sanitizer.call(name) else name .gsub(/[^a-zA-Z0-9_\-.]/, "_") .gsub(/_+/, "_") .gsub(/\A_|_\z/, "") end end |
.strip_test_prefix(name) ⇒ String
: (String) -> String
33 34 35 |
# File 'lib/insta/snapshot_name.rb', line 33 def self.strip_test_prefix(name) name.sub(/\Atest_(\d+_)?/, "") end |
.underscore(string) ⇒ String
: (String) -> String
22 23 24 25 26 27 28 29 30 |
# File 'lib/insta/snapshot_name.rb', line 22 def self.underscore(string) string .gsub("::", "/") .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .tr(" ", "_") .downcase end |