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+, 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.
382 383 384 385 386 |
# File 'lib/tina4/seeder.rb', line 382 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.
380 381 382 |
# File 'lib/tina4/seeder.rb', line 380 def errors @errors end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
380 381 382 |
# File 'lib/tina4/seeder.rb', line 380 def failed @failed end |
#seeded ⇒ Object (readonly)
Returns the value of attribute seeded.
380 381 382 |
# File 'lib/tina4/seeder.rb', line 380 def seeded @seeded end |
Instance Method Details
#<=>(other) ⇒ Object
428 429 430 |
# File 'lib/tina4/seeder.rb', line 428 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.
405 406 407 408 409 410 411 412 |
# File 'lib/tina4/seeder.rb', line 405 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
400 401 402 |
# File 'lib/tina4/seeder.rb', line 400 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.
424 425 426 |
# File 'lib/tina4/seeder.rb', line 424 def coerce(other) [other, @seeded] end |
#eql?(other) ⇒ Boolean
414 415 416 |
# File 'lib/tina4/seeder.rb', line 414 def eql?(other) other.is_a?(SeedSummary) && to_h == other.to_h end |
#hash ⇒ Object
418 419 420 |
# File 'lib/tina4/seeder.rb', line 418 def hash to_h.hash end |
#to_h ⇒ Object Also known as: to_hash
394 395 396 |
# File 'lib/tina4/seeder.rb', line 394 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).
389 390 391 |
# File 'lib/tina4/seeder.rb', line 389 def to_i @seeded end |
#to_json(*args) ⇒ Object
433 434 435 |
# File 'lib/tina4/seeder.rb', line 433 def to_json(*args) to_h.to_json(*args) end |
#to_s ⇒ Object Also known as: inspect
437 438 439 |
# File 'lib/tina4/seeder.rb', line 437 def to_s "SeedSummary(seeded=#{@seeded}, failed=#{@failed}, errors=#{@errors.inspect})" end |