Class: JeraPaymentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/jera_payment/jera_payment_generator.rb

Constant Summary collapse

MissingModel =
Class.new(Thor::Error)

Instance Method Summary collapse

Instance Method Details

#generate_relationObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/jera_payment/jera_payment_generator.rb', line 7

def generate_relation
  unless model_exists?
    raise MissingModel,
    "\n\tModel \"#{file_name.titlecase}\" doesn't exists. Please, create your Model and try again."
  end

  unless args.present?
    raise MissingModel,
    "\n\tYou need to pass an JeraPayment Model (Customer or/and SubAccount)"
  end

  args.each do |arg|
    inject_into_file model_path, "\n\thas_one :#{arg.underscore}, as: :#{polymorfic_model_name(arg)}, class_name: 'JeraPayment::#{arg}'", after: '< ActiveRecord::Base'

    inject_into_file model_path, "\n\thas_one :#{arg.underscore}, as: :#{polymorfic_model_name(arg)}, class_name: 'JeraPayment::#{arg}'", after: '< ApplicationRecord'
  end

end