Class: ForgeCLI::PostPostHooks

Inherits:
PostHooks show all
Defined in:
lib/forge-cli/modules/posts/post_hooks.rb

Instance Method Summary collapse

Methods inherited from PostHooks

#initialize, run!

Constructor Details

This class inherits a constructor from ForgeCLI::PostHooks

Instance Method Details

#app_controller_contentObject



28
29
30
# File 'lib/forge-cli/modules/posts/post_hooks.rb', line 28

def app_controller_content
  @app_controller_content ||= File.read(app_controller_path)
end

#app_controller_pathObject



24
25
26
# File 'lib/forge-cli/modules/posts/post_hooks.rb', line 24

def app_controller_path
  File.join(@app, 'app', 'controllers', 'application_controller.rb')
end

#module_pathObject



20
21
22
# File 'lib/forge-cli/modules/posts/post_hooks.rb', line 20

def module_path
  File.dirname(__FILE__)
end

#run!Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/forge-cli/modules/posts/post_hooks.rb', line 2

def run!
  STDOUT.puts "Adding Routes..."
  ri = ForgeCLI::RouteInstaller.new(@app, module_path)
  ri.install_routes
  ri.install_routes(:forge)

  STDOUT.puts "Adding Posts controller methods..."
  content = app_controller_content.gsub(
      'class ApplicationController < ActionController::Base',
      "class ApplicationController < ActionController::Base\n  include Forge::Controllers::Posts\n"
  )
  content = "require 'forge/shared_controller_methods/posts.rb'\n" + content
  File.open(app_controller_path, 'w') do |f|
    f.puts content
  end
end