Class: FactoryBotGenerator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot_generator.rb

Constant Summary collapse

QUOTE_AROUND_VALUE_TYPES =
i[string date datetime text].freeze
EXCLUDE_COLUMNS =
%w[created_at updated_at].freeze
TEMPLATE_PATH =
File.join(File.dirname(__FILE__), 'factory_bot_generator.erb')
TEMPLATE =
File.read(TEMPLATE_PATH)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, options) ⇒ Base

Returns a new instance of Base.



16
17
18
19
# File 'lib/factory_bot_generator.rb', line 16

def initialize(record, options)
  @record = record
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/factory_bot_generator.rb', line 21

def options
  @options
end

#recordObject (readonly)

Returns the value of attribute record.



21
22
23
# File 'lib/factory_bot_generator.rb', line 21

def record
  @record
end

Class Method Details

.render(record, options = {}) ⇒ Object



12
13
14
# File 'lib/factory_bot_generator.rb', line 12

def self.render(record, options = {})
  new(record, options).render
end

Instance Method Details

#renderObject



23
24
25
# File 'lib/factory_bot_generator.rb', line 23

def render
  render_long + "\n" + render_short
end

#render_longObject



27
28
29
# File 'lib/factory_bot_generator.rb', line 27

def render_long
  ERB.new(TEMPLATE, trim_mode: '-').result(binding)
end

#render_shortObject



31
32
33
34
# File 'lib/factory_bot_generator.rb', line 31

def render_short
  columns.reject! { record.public_send(_1).blank? }
  ERB.new(TEMPLATE, trim_mode: '-').result(binding)
end