Class: Errata

Inherits:
Object
  • Object
show all
Defined in:
lib/errata.rb,
lib/errata/erratum.rb,
lib/errata/version.rb,
lib/errata/erratum/delete.rb,
lib/errata/erratum/reject.rb,
lib/errata/erratum/replace.rb,
lib/errata/erratum/simplify.rb,
lib/errata/erratum/truncate.rb,
lib/errata/erratum/transform.rb

Defined Under Namespace

Classes: Erratum

Constant Summary collapse

CORRECTIONS =
%w{delete replace simplify transform truncate reject}
VERSION =
'1.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Errata

Arguments

  • :responder (required) - normally you pass this something like Guru.new, which should respond to questions like #is_a_bentley?. If you pass a string, it will be lazily constantized and a new object initialized from it; for example, ‘Guru’ will lead to ‘Guru’.constantize.new.

  • :table - takes something that acts like a RemoteTable

If and only if you don’t pass :table, all other options will be passed to a new RemoteTable (for example, :url, etc.)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/errata.rb', line 22

def initialize(options = {})
  options = options.symbolize_keys

  responder = options.delete :responder
  if responder.is_a?(::String)
    @lazy_load_responder_mutex = ::Mutex.new
    @lazy_load_responder_class_name = responder
  elsif responder
    ::Kernel.warn %{[errata] Passing an object as :responder is deprecated. It's recommended to pass a class name instead, which will be constantized and instantiated with no arguments.}
    @responder = responder
  else
    @no_responder = true
  end

  if table = options.delete(:table)
    ::Kernel.warn %{[errata] Passing :table is deprecated. It's recommended to pass table options instead.}
    @table = table
  else
    @lazy_load_table_options = options
  end

  @set_rejections_and_corrections_mutex = ::Mutex.new
end

Instance Attribute Details

#lazy_load_responder_class_nameObject (readonly)

Returns the value of attribute lazy_load_responder_class_name.



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

def lazy_load_responder_class_name
  @lazy_load_responder_class_name
end

#lazy_load_table_optionsObject (readonly)

Returns the value of attribute lazy_load_table_options.



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

def lazy_load_table_options
  @lazy_load_table_options
end

Instance Method Details

#correct!(row) ⇒ Object



50
51
52
53
# File 'lib/errata.rb', line 50

def correct!(row)
  corrections.each { |erratum| erratum.correct!(row) }
  nil
end

#rejects?(row) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/errata.rb', line 46

def rejects?(row)
  rejections.any? { |erratum| erratum.targets?(row) }
end

#responderObject



55
56
57
58
59
60
# File 'lib/errata.rb', line 55

def responder
  return if @no_responder == true
  @responder || @lazy_load_responder_mutex.synchronize do
    @responder ||= lazy_load_responder_class_name.constantize.new
  end
end