Class: Pact::Support::Configuration
- Inherits:
-
Object
- Object
- Pact::Support::Configuration
- Defined in:
- lib/pact/support/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 =
[ [/multipart\/form-data/, Pact::Matchers::MultipartFormDiffFormatter], [/.*/, Pact::Matchers::UnixDiffFormatter], [NilMatcher, Pact::Matchers::UnixDiffFormatter] ]
- DIFFERS =
[ [/json/, Pact::JsonDiffer], [/application\/x\-www\-form\-urlencoded/, Pact::FormDiffer], [/multipart\/form-data/, Pact::MultipartFormDiffer], [NilMatcher, Pact::TextDiffer], [/.*/, Pact::TextDiffer] ]
- DEFAULT_DIFFER =
Pact::TextDiffer
Instance Attribute Summary collapse
-
#error_stream ⇒ Object
Returns the value of attribute error_stream.
-
#log_dir ⇒ Object
Returns the value of attribute log_dir.
- #logger ⇒ Object
-
#output_stream ⇒ Object
Returns the value of attribute output_stream.
-
#pact_dir ⇒ Object
Returns the value of attribute pact_dir.
-
#pactfile_write_order ⇒ Object
Returns the value of attribute pactfile_write_order.
-
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
-
#treat_all_number_classes_as_equivalent ⇒ Object
when using type based matching.
Class Method Summary collapse
Instance Method Summary collapse
- #body_differ_for_content_type(content_type) ⇒ Object
- #color_enabled ⇒ Object
- #color_enabled=(color_enabled) ⇒ Object
-
#diff_formatter=(diff_formatter) ⇒ Object
Should this be deprecated in favour of register_diff_formatter???.
- #diff_formatter_for_content_type(content_type) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #log_path ⇒ Object
- #register_body_differ(content_type, differ) ⇒ Object
- #register_diff_formatter(content_type, diff_formatter) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
72 73 74 75 |
# File 'lib/pact/support/configuration.rb', line 72 def initialize @differ_registrations = [] @diff_formatter_registrations = [] end |
Instance Attribute Details
#error_stream ⇒ Object
Returns the value of attribute error_stream.
53 54 55 |
# File 'lib/pact/support/configuration.rb', line 53 def error_stream @error_stream end |
#log_dir ⇒ Object
Returns the value of attribute log_dir.
48 49 50 |
# File 'lib/pact/support/configuration.rb', line 48 def log_dir @log_dir end |
#logger ⇒ Object
77 78 79 |
# File 'lib/pact/support/configuration.rb', line 77 def logger @logger ||= create_logger end |
#output_stream ⇒ Object
Returns the value of attribute output_stream.
54 55 56 |
# File 'lib/pact/support/configuration.rb', line 54 def output_stream @output_stream end |
#pact_dir ⇒ Object
Returns the value of attribute pact_dir.
47 48 49 |
# File 'lib/pact/support/configuration.rb', line 47 def pact_dir @pact_dir end |
#pactfile_write_order ⇒ Object
Returns the value of attribute pactfile_write_order.
55 56 57 |
# File 'lib/pact/support/configuration.rb', line 55 def pactfile_write_order @pactfile_write_order end |
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
49 50 51 |
# File 'lib/pact/support/configuration.rb', line 49 def tmp_dir @tmp_dir end |
#treat_all_number_classes_as_equivalent ⇒ Object
when using type based matching
56 57 58 |
# File 'lib/pact/support/configuration.rb', line 56 def treat_all_number_classes_as_equivalent @treat_all_number_classes_as_equivalent end |
Class Method Details
.default_configuration ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pact/support/configuration.rb', line 58 def self.default_configuration c = Configuration.new c.pact_dir = File.('./spec/pacts') c.tmp_dir = File.('./tmp/pacts') c.log_dir = default_log_dir c.output_stream = $stdout c.error_stream = $stderr c.pactfile_write_order = :chronological c.treat_all_number_classes_as_equivalent = true c end |
.default_log_dir ⇒ Object
164 165 166 |
# File 'lib/pact/support/configuration.rb', line 164 def self.default_log_dir File.("./log") end |
Instance Method Details
#body_differ_for_content_type(content_type) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pact/support/configuration.rb', line 102 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_enabled ⇒ Object
117 118 119 120 121 122 |
# File 'lib/pact/support/configuration.rb', line 117 def color_enabled # Can't use ||= when the variable might be false, it will execute the expression if it's false color_enabled = defined?(@color_enabled) ? @color_enabled : true Rainbow.enabled = true if color_enabled color_enabled end |
#color_enabled=(color_enabled) ⇒ Object
124 125 126 |
# File 'lib/pact/support/configuration.rb', line 124 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???
82 83 84 85 |
# File 'lib/pact/support/configuration.rb', line 82 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
92 93 94 |
# File 'lib/pact/support/configuration.rb', line 92 def diff_formatter_for_content_type content_type diff_formatter_registrations.find{ | registration | registration.first =~ content_type }.last end |
#log_path ⇒ Object
113 114 115 |
# File 'lib/pact/support/configuration.rb', line 113 def log_path log_dir + "/pact.log" end |
#register_body_differ(content_type, differ) ⇒ Object
96 97 98 99 100 |
# File 'lib/pact/support/configuration.rb', line 96 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
87 88 89 90 |
# File 'lib/pact/support/configuration.rb', line 87 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 |