Class: Payfast::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/payfast/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_erb_tagObject



41
42
43
44
45
46
# File 'lib/generators/payfast/install_generator.rb', line 41

def add_erb_tag
  # Append an ERB tag to the application.html.erb file
  insert_into_file "app/views/layouts/application.html.erb", before: "</head>" do
    "<%= payfast_script_tag %>"
  end
end

#configure_developmentObject



48
49
50
51
52
53
54
# File 'lib/generators/payfast/install_generator.rb', line 48

def configure_development
  insert_into_file "config/environments/development.rb", before: /^end/ do
    <<-RUBY.strip_heredoc.indent(2)
        config.hosts << /[a-z0-9-]+\.ngrok-free\.app/
    RUBY
  end
end

#create_config_fileObject



33
34
35
# File 'lib/generators/payfast/install_generator.rb', line 33

def create_config_file
  template "config.yml", "config/payfast.yml"
end

#create_controllerObject



15
16
17
# File 'lib/generators/payfast/install_generator.rb', line 15

def create_controller
  template "controller.rb", File.join("app/controllers", "#{controller_file_name}_controller.rb")
end

#create_migrationObject



29
30
31
# File 'lib/generators/payfast/install_generator.rb', line 29

def create_migration
  template "migration.rb", "db/migrate/#{timestamp}_create_carts.rb"
end

#create_modelObject



37
38
39
# File 'lib/generators/payfast/install_generator.rb', line 37

def create_model
  template "model.rb", "app/models/cart.rb"
end

#create_view_helperObject



25
26
27
# File 'lib/generators/payfast/install_generator.rb', line 25

def create_view_helper
  template "helper.rb", "app/helpers/carts_helper.rb"
end

#create_viewsObject



19
20
21
22
23
# File 'lib/generators/payfast/install_generator.rb', line 19

def create_views
  actions.each do |action|
    template "#{action}.html.erb", File.join("app/views", controller_file_name, "#{action}.html.erb")
  end
end

#modify_routesObject



8
9
10
11
12
13
# File 'lib/generators/payfast/install_generator.rb', line 8

def modify_routes
  insert_into_file "config/routes.rb", after: "Rails.application.routes.draw do\n" do
    # Read and insert the contents of your routes template file
    File.read(File.join(__dir__, "templates", "routes.rb"))
  end
end