Class: Ekylibre::FirstRun::Faker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ekylibre/first_run/faker/base.rb

Direct Known Subclasses

Crumbs, Interventions, Prescriptions, Sales

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.


9
10
11
# File 'lib/ekylibre/first_run/faker/base.rb', line 9

def initialize(options = {})
  @max = options[:max] || 0
end

Class Method Details

.run(options = {}) ⇒ Object


5
6
7
# File 'lib/ekylibre/first_run/faker/base.rb', line 5

def self.run(options = {})
  new(options).run
end

Instance Method Details

#count(name, options = {}, &_block) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ekylibre/first_run/faker/base.rb', line 21

def count(name, options = {}, &_block)
  STDOUT.sync = true
  f = Ekylibre::FirstRun::Counter.new(@max) do |_count, _increment|
    print '.'
  end
  start = Time.zone.now
  label_size = options[:label_size] || 21
  label = name.to_s.humanize.rjust(label_size)
  label = Ekylibre::FirstRun::Base.ellipse(label, label_size)
  print "[#{'FAKE'.magenta}] #{label.blue}: "
  begin
    yield(f)
    print ' ' * (@max - f.count) if @max > 0 && @max > f.count
    print '  '
  rescue Ekylibre::FirstRun::Counter::CountExceeded => e
    print '! '
  end
  puts "#{(Time.zone.now - start).round(2).to_s.rjust(6)}s"
end

#filesObject


13
14
15
# File 'lib/ekylibre/first_run/faker/base.rb', line 13

def files
  Pathname.new(__FILE__).dirname.join('files')
end

#path(*args) ⇒ Object


17
18
19
# File 'lib/ekylibre/first_run/faker/base.rb', line 17

def path(*args)
  files.join(*args)
end