Class: Insta::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/insta/configuration.rb,
sig/insta/configuration.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

: () -> void



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/insta/configuration.rb', line 24

def initialize
  @snapshot_path = "test/snapshots"
  @diff_display = :side_by_side
  @diff_width = nil
  @diff_color = :auto
  @update_mode = :auto
  @default_serializer = :to_s
  @heredoc_identifier = "SNAP"
  @ci_mode = :auto
  @snapshot_extension = ".snap"
  @snapshot_sanitizer = nil
  @snapshot_filename = nil
  @snapshot_directory = nil
  @new_snapshot = :review
end

Instance Attribute Details

#ci_modeSymbol

: Symbol

Returns:

  • (Symbol)


16
17
18
# File 'lib/insta/configuration.rb', line 16

def ci_mode
  @ci_mode
end

#default_serializerSymbol

: Symbol

Returns:

  • (Symbol)


14
15
16
# File 'lib/insta/configuration.rb', line 14

def default_serializer
  @default_serializer
end

#diff_colorSymbol

: Symbol

Returns:

  • (Symbol)


12
13
14
# File 'lib/insta/configuration.rb', line 12

def diff_color
  @diff_color
end

#diff_displaySymbol

: Symbol

Returns:

  • (Symbol)


10
11
12
# File 'lib/insta/configuration.rb', line 10

def diff_display
  @diff_display
end

#diff_widthInteger?

: Integer?

Returns:

  • (Integer, nil)


11
12
13
# File 'lib/insta/configuration.rb', line 11

def diff_width
  @diff_width
end

#heredoc_identifierString

: String

Returns:

  • (String)


15
16
17
# File 'lib/insta/configuration.rb', line 15

def heredoc_identifier
  @heredoc_identifier
end

#new_snapshotSymbol

: Symbol

Returns:

  • (Symbol)


21
22
23
# File 'lib/insta/configuration.rb', line 21

def new_snapshot
  @new_snapshot
end

#snapshot_directory^(test_class: String) -> String?

: (^(test_class: String) -> String)?

Returns:

  • (^(test_class: String) -> String, nil)


20
21
22
# File 'lib/insta/configuration.rb', line 20

def snapshot_directory
  @snapshot_directory
end

#snapshot_extensionString

: String

Returns:

  • (String)


17
18
19
# File 'lib/insta/configuration.rb', line 17

def snapshot_extension
  @snapshot_extension
end

#snapshot_filenamesnapshot_filename_resolver?

: snapshot_filename_resolver?

Returns:

  • (snapshot_filename_resolver, nil)


19
20
21
# File 'lib/insta/configuration.rb', line 19

def snapshot_filename
  @snapshot_filename
end

#snapshot_pathString

@rbs! type snapshot_filename_resolver = ^(test_name: String, counter: Integer, options: Hash[Symbol, untyped]) -> String

Returns:

  • (String)


9
10
11
# File 'lib/insta/configuration.rb', line 9

def snapshot_path
  @snapshot_path
end

#snapshot_sanitizer^(String) -> String?

: (^(String) -> String)?

Returns:

  • (^(String) -> String, nil)


18
19
20
# File 'lib/insta/configuration.rb', line 18

def snapshot_sanitizer
  @snapshot_sanitizer
end

#update_modeSymbol

: Symbol

Returns:

  • (Symbol)


13
14
15
# File 'lib/insta/configuration.rb', line 13

def update_mode
  @update_mode
end

Instance Method Details

#resolved_ci_mode?Boolean

: () -> bool

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/insta/configuration.rb', line 59

def resolved_ci_mode?
  case @ci_mode
  when :auto then CI.ci?
  when true then true
  else false
  end
end

#resolved_diff_colorString

: () -> String

Returns:

  • (String)


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/insta/configuration.rb', line 68

def resolved_diff_color
  return "never" if ENV.key?("NO_COLOR")

  case @diff_color
  when :always then "always"
  when :never then "never"
  when :auto
    $stdout.tty? ? "always" : "never"
  else
    "auto"
  end
end

#resolved_diff_displayString

: () -> String

Returns:

  • (String)


82
83
84
85
86
87
# File 'lib/insta/configuration.rb', line 82

def resolved_diff_display
  case @diff_display
  when :inline then "inline"
  else "side-by-side-show-both"
  end
end

#resolved_update_modeSymbol

: () -> Symbol

Returns:

  • (Symbol)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/insta/configuration.rb', line 41

def resolved_update_mode
  if ENV["INSTA_UPDATE"]
    case ENV.fetch("INSTA_UPDATE", nil)
    when "always", "force" then :force
    when "new" then :new
    when "no" then :no
    else :auto
    end
  elsif ENV["INSTA_FORCE_PASS"]
    :pending
  elsif resolved_ci_mode?
    :no
  else
    @update_mode
  end
end