Class: Tina4::SeedSummary
- Inherits:
-
Object
- Object
- Tina4::SeedSummary
- Includes:
- Comparable
- Defined in:
- lib/tina4/seeder.rb
Overview
Result of a seed run — {seeded, failed, errors}.
Mirrors the Python master’s SeedSummary(int). Ruby has no int subclass, but the OLD seed helpers returned the inserted count as an Integer and specs assert on it (+expect(count).to eq(5)+). To keep that contract intact while exposing the new struct, SeedSummary defines to_i, == (against an Integer or another SeedSummary), to_int (implicit coercion) and Hash-style read access (summary[:seeded], to_h) so it behaves like the seeded count where an Integer is expected and like the struct everywhere else.
errors is a list of { row: <0-based index>, message: <str> } hashes describing every skipped row.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#seeded ⇒ Object
readonly
Returns the value of attribute seeded.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Object
Compare equal to a bare Integer (the seeded count) OR another summary.
- #[](key) ⇒ Object
-
#coerce(other) ⇒ Object
Arithmetic / ordering against Integers so existing numeric assertions (e.g. be >= 1, count 1+) keep working.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(seeded: 0, failed: 0, errors: nil) ⇒ SeedSummary
constructor
A new instance of SeedSummary.
- #to_h ⇒ Object (also: #to_hash)
-
#to_i ⇒ Object
(also: #to_int)
Integer value == seeded (preserves the pre-overhaul count contract).
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(seeded: 0, failed: 0, errors: nil) ⇒ SeedSummary
Returns a new instance of SeedSummary.
368 369 370 371 372 |
# File 'lib/tina4/seeder.rb', line 368 def initialize(seeded: 0, failed: 0, errors: nil) @seeded = seeded.to_i @failed = failed.to_i @errors = errors || [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
366 367 368 |
# File 'lib/tina4/seeder.rb', line 366 def errors @errors end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
366 367 368 |
# File 'lib/tina4/seeder.rb', line 366 def failed @failed end |
#seeded ⇒ Object (readonly)
Returns the value of attribute seeded.
366 367 368 |
# File 'lib/tina4/seeder.rb', line 366 def seeded @seeded end |
Instance Method Details
#<=>(other) ⇒ Object
414 415 416 |
# File 'lib/tina4/seeder.rb', line 414 def <=>(other) @seeded <=> (other.is_a?(SeedSummary) ? other.to_i : other) end |
#==(other) ⇒ Object
Compare equal to a bare Integer (the seeded count) OR another summary.
391 392 393 394 395 396 397 398 |
# File 'lib/tina4/seeder.rb', line 391 def ==(other) case other when Integer then @seeded == other when SeedSummary then to_h == other.to_h when Hash then to_h == other else false end end |
#[](key) ⇒ Object
386 387 388 |
# File 'lib/tina4/seeder.rb', line 386 def [](key) to_h[key.to_sym] end |
#coerce(other) ⇒ Object
Arithmetic / ordering against Integers so existing numeric assertions (e.g. be >= 1, count 1+) keep working.
410 411 412 |
# File 'lib/tina4/seeder.rb', line 410 def coerce(other) [other, @seeded] end |
#eql?(other) ⇒ Boolean
400 401 402 |
# File 'lib/tina4/seeder.rb', line 400 def eql?(other) other.is_a?(SeedSummary) && to_h == other.to_h end |
#hash ⇒ Object
404 405 406 |
# File 'lib/tina4/seeder.rb', line 404 def hash to_h.hash end |
#to_h ⇒ Object Also known as: to_hash
380 381 382 |
# File 'lib/tina4/seeder.rb', line 380 def to_h { seeded: @seeded, failed: @failed, errors: @errors } end |
#to_i ⇒ Object Also known as: to_int
Integer value == seeded (preserves the pre-overhaul count contract).
375 376 377 |
# File 'lib/tina4/seeder.rb', line 375 def to_i @seeded end |
#to_json(*args) ⇒ Object
419 420 421 |
# File 'lib/tina4/seeder.rb', line 419 def to_json(*args) to_h.to_json(*args) end |
#to_s ⇒ Object Also known as: inspect
423 424 425 |
# File 'lib/tina4/seeder.rb', line 423 def to_s "SeedSummary(seeded=#{@seeded}, failed=#{@failed}, errors=#{@errors.inspect})" end |