Class: Clearance::Generators::RoutesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/clearance/routes/routes_generator.rb

Instance Method Summary collapse

Instance Method Details

#clearance_routesObject (private)


22
23
24
# File 'lib/generators/clearance/routes/routes_generator.rb', line 22

def clearance_routes
  File.read(routes_file_path)
end

#disable_clearance_internal_routesObject


12
13
14
15
16
17
18
# File 'lib/generators/clearance/routes/routes_generator.rb', line 12

def disable_clearance_internal_routes
  inject_into_file(
    "config/initializers/clearance.rb",
    "  config.routes = false\n",
    after: "Clearance.configure do |config|\n",
  )
end

#inject_clearance_routes_into_application_routesObject


8
9
10
# File 'lib/generators/clearance/routes/routes_generator.rb', line 8

def inject_clearance_routes_into_application_routes
  route(clearance_routes)
end

#route(routing_code) ⇒ Object (private)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/clearance/routes/routes_generator.rb', line 30

def route(routing_code)
  log :route, "all clearance routes"
  sentinel = /\.routes\.draw do\s*\n/m

  in_root do
    inject_into_file(
      "config/routes.rb",
      routing_code,
      after: sentinel,
      verbose: false,
      force: true,
    )
  end
end

#routes_file_pathObject (private)


26
27
28
# File 'lib/generators/clearance/routes/routes_generator.rb', line 26

def routes_file_path
  File.expand_path(find_in_source_paths('routes.rb'))
end