Class: Pact::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/configuration.rb

Defined Under Namespace

Classes: NilMatcher

Constant Summary collapse

DIFF_FORMATTERS =
{
  :embedded => Pact::Matchers::EmbeddedDiffFormatter,
  :unix => Pact::Matchers::UnixDiffFormatter,
  :list => Pact::Matchers::ListDiffFormatter
}
DIFF_FORMATTER_REGISTRATIONS =
[
  [/.*/, Pact::Matchers::UnixDiffFormatter],
  [NilMatcher, Pact::Matchers::UnixDiffFormatter]
]
DIFFERS =
[
  [/json/, Pact::JsonDiffer],
  [/application\/x\-www\-form\-urlencoded/, Pact::FormDiffer],
  [NilMatcher, Pact::TextDiffer],
  [/.*/, Pact::TextDiffer]
]
DEFAULT_DIFFER =
Pact::TextDiffer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



64
65
66
67
# File 'lib/pact/configuration.rb', line 64

def initialize
  @differ_registrations = []
  @diff_formatter_registrations = []
end

Instance Attribute Details

#error_streamObject

Returns the value of attribute error_stream.



47
48
49
# File 'lib/pact/configuration.rb', line 47

def error_stream
  @error_stream
end

#log_dirObject

Returns the value of attribute log_dir.



42
43
44
# File 'lib/pact/configuration.rb', line 42

def log_dir
  @log_dir
end

#loggerObject



69
70
71
# File 'lib/pact/configuration.rb', line 69

def logger
  @logger ||= create_logger
end

#output_streamObject

Returns the value of attribute output_stream.



48
49
50
# File 'lib/pact/configuration.rb', line 48

def output_stream
  @output_stream
end

#pact_dirObject

Returns the value of attribute pact_dir.



41
42
43
# File 'lib/pact/configuration.rb', line 41

def pact_dir
  @pact_dir
end

#pactfile_write_orderObject

Returns the value of attribute pactfile_write_order.



49
50
51
# File 'lib/pact/configuration.rb', line 49

def pactfile_write_order
  @pactfile_write_order
end

#tmp_dirObject

Returns the value of attribute tmp_dir.



43
44
45
# File 'lib/pact/configuration.rb', line 43

def tmp_dir
  @tmp_dir
end

Class Method Details

.default_configurationObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pact/configuration.rb', line 51

def self.default_configuration
  c = Configuration.new
  c.pact_dir = File.expand_path('./spec/pacts')
  c.tmp_dir = File.expand_path('./tmp/pacts')
  c.log_dir = default_log_dir

  c.output_stream = $stdout
  c.error_stream = $stderr
  c.pactfile_write_order = :chronological

  c
end

Instance Method Details

#body_differ_for_content_type(content_type) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/pact/configuration.rb', line 94

def body_differ_for_content_type content_type
  differ_registrations
    .find{ | registration | registration.first =~ content_type }
    .tap do |it|
      if content_type.nil? && it.last == Pact::TextDiffer
        error_stream.puts "WARN: No content type found, performing text diff on body"
        logger.warn "No content type found, performing text diff on body"
      end
    end.last
end

#color_enabledObject



109
110
111
112
# File 'lib/pact/configuration.rb', line 109

def color_enabled
  # Can't use ||= when the variable might be false, it will execute the expression if it's false
  defined?(@color_enabled) ? @color_enabled : true
end

#color_enabled=(color_enabled) ⇒ Object



114
115
116
# File 'lib/pact/configuration.rb', line 114

def color_enabled= color_enabled
  @color_enabled = color_enabled
end

#diff_formatter=(diff_formatter) ⇒ Object

Should this be deprecated in favour of register_diff_formatter???



74
75
76
77
# File 'lib/pact/configuration.rb', line 74

def diff_formatter= diff_formatter
  register_diff_formatter /.*/, diff_formatter
  register_diff_formatter nil, diff_formatter
end

#diff_formatter_for_content_type(content_type) ⇒ Object



84
85
86
# File 'lib/pact/configuration.rb', line 84

def diff_formatter_for_content_type content_type
  diff_formatter_registrations.find{ | registration | registration.first =~ content_type }.last
end

#log_pathObject



105
106
107
# File 'lib/pact/configuration.rb', line 105

def log_path
  log_dir + "/pact.log"
end

#register_body_differ(content_type, differ) ⇒ Object



88
89
90
91
92
# File 'lib/pact/configuration.rb', line 88

def register_body_differ content_type, differ
  key = content_type_regexp_for content_type
  validate_differ differ
  @differ_registrations << [key, differ]
end

#register_diff_formatter(content_type, diff_formatter) ⇒ Object



79
80
81
82
# File 'lib/pact/configuration.rb', line 79

def register_diff_formatter content_type, diff_formatter
  key = content_type_regexp_for content_type
  @diff_formatter_registrations << [key, diff_formatter_for(diff_formatter)]
end