Module: SeedGen::FakerData

Defined in:
lib/seedgen/faker.rb

Defined Under Namespace

Classes: InvalidAttributeType

Class Method Summary collapse

Class Method Details

.enum?(model, column) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/seedgen/faker.rb', line 47

def self.enum?(model, column)
  model.defined_enums.key?(column)
end

.generate(model, column) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/seedgen/faker.rb', line 7

def self.generate(model, column)
  case column..type
  when :binary
    Faker::Number.binary
  when :boolean
    # TODO
    true
  when :date
    # TODO
    Faker::Date.random
  when :datetime
    Faker::Date.random
  when :decimal
    Faker::Number.decimal
  when :float
    3.03
  when :integer
    # TODO
    if enum?(model, column.name)
      range = model.defined_enums[column.name].length - 1
      return Faker::Number.between(from: 0, to: range)
    end
    Faker::Number.number(digits: 4)
  when :bigint
    Faker::Number.number(digits: 10)
  when :string
    Faker::Alphanumeric.alpha(number: 7)
  when :text
    Faker::Company.bs
  when :time
    # TODO
    Faker::Date.time
  when :timestamp
    # TODO
    Faker::Date.time
  else
    raise InvalidAttributeType
  end
end