Class: Thredded::DatabaseSeeder::BaseSeedData

Inherits:
Object
  • Object
show all
Includes:
LogTime
Defined in:
lib/thredded/database_seeder.rb

Direct Known Subclasses

CollectionSeedData, FirstSeedData

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LogTime

included, #log_time, #print_time_diff

Constructor Details

#initialize(seed_database = DatabaseSeeder.new) ⇒ BaseSeedData

Returns a new instance of BaseSeedData.



254
255
256
# File 'lib/thredded/database_seeder.rb', line 254

def initialize(seed_database = DatabaseSeeder.new)
  @seeder = seed_database
end

Instance Attribute Details

#seederThredded::DatabaseSeeder (readonly)



252
253
254
# File 'lib/thredded/database_seeder.rb', line 252

def seeder
  @seeder
end

Class Method Details

.create(*args) ⇒ Object

Utility method



259
260
261
# File 'lib/thredded/database_seeder.rb', line 259

def self.create(*args)
  new.create(*args)
end

Instance Method Details

#find_or_create(*args, **kwargs) ⇒ Object



265
266
267
268
# File 'lib/thredded/database_seeder.rb', line 265

def find_or_create(*args, **kwargs)
  return @stored if @stored
  @stored = (find || create(*args, **kwargs))
end

#range_of_dates_in_order(up_to: Time.zone.now, count: 1) ⇒ Object



270
271
272
273
# File 'lib/thredded/database_seeder.rb', line 270

def range_of_dates_in_order(up_to: Time.zone.now, count: 1)
  written = up_to
  Array.new(count - 1) { written -= random_duration(10.minutes..6.hours) }.reverse + [up_to]
end