Class: DirtySeed::Logger
- Inherits:
-
Object
- Object
- DirtySeed::Logger
- Includes:
- Singleton
- Defined in:
- lib/dirty_seed/logger.rb
Overview
Represents an Active Record model
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#abort ⇒ void
Outputs an abort message.
-
#clean(message) ⇒ Object
Cleans the message before output (remove linebreak and truncate).
-
#failure ⇒ void
Outputs a fail message.
-
#seed_model_message(model) ⇒ void
Outputs before seeding a model.
-
#success ⇒ void
Outputs a success message.
-
#summary(seeders) ⇒ void
Outputs seeder data.
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/dirty_seed/logger.rb', line 9 def verbose @verbose end |
Instance Method Details
#abort ⇒ void
This method returns an undefined value.
Outputs an abort message
45 46 47 |
# File 'lib/dirty_seed/logger.rb', line 45 def abort verbose && print("\e[31m | too many errors -> abort\e[0m") end |
#clean(message) ⇒ Object
Cleans the message before output (remove linebreak and truncate)
25 26 27 28 29 |
# File 'lib/dirty_seed/logger.rb', line 25 def clean() base = .tr("\n", "\t") # #truncate is defined in ActiveSupport and then could be undefined base.respond_to?(:truncate) ? base.truncate(150) : base.slice(150) end |
#failure ⇒ void
This method returns an undefined value.
Outputs a fail message
39 40 41 |
# File 'lib/dirty_seed/logger.rb', line 39 def failure verbose && print("\e[31mx\e[0m") end |
#seed_model_message(model) ⇒ void
This method returns an undefined value.
Outputs before seeding a model
14 15 16 17 18 19 20 |
# File 'lib/dirty_seed/logger.rb', line 14 def (model) return unless verbose puts('') puts("Seeding #{model.name.underscore.pluralize}") print('> ') end |
#success ⇒ void
This method returns an undefined value.
Outputs a success message
33 34 35 |
# File 'lib/dirty_seed/logger.rb', line 33 def success verbose && print("\e[32m.\e[0m") end |
#summary(seeders) ⇒ void
This method returns an undefined value.
Outputs seeder data
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dirty_seed/logger.rb', line 51 def summary(seeders) return unless verbose puts '' seeders.each do |seeder| puts seeder.model.name puts " \e[32mseeded: #{seeder.records.count}\e[0m" puts " \e[31merrors: #{seeder.errors.join(', ')}\e[0m" if seeder.errors.any? end end |