Sha256: 85f20128da1fa3b5ca23701095c6fe0b4f548dbf0325938ad770a3a4e927f143
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
class ForgeCLI class RouteInstaller def initialize(app, module_path) @app = app @module_path = module_path end def install_routes(type = :normal) file = File.join(@app, 'config', 'routes.rb') existing_routes = File.read(file) if type.to_sym == :normal routes_to_add = routes line = "Application.routes.draw do" indent = 2 else routes_to_add = self.send("#{type}_routes") line = "namespace :#{type} do" indent = 4 end routes = routes_to_add.split("\n").map {|r| " " * indent + r }.join("\n") updated_routes = existing_routes.gsub(line, "#{line}\n#{routes}") File.open(file, 'w') do |f| f.puts updated_routes end end def routes @routes ||= get_routes end def forge_routes @forge_routes ||= get_routes('forge_') end def get_routes(prefix = '') file = File.join(@module_path, "#{prefix}routes.rb") if File.exist?(file) File.open(file, "r").read end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
forge-cli-0.0.8 | lib/forge-cli/route_installer.rb |
forge-cli-0.0.7 | lib/forge-cli/route_installer.rb |
forge-cli-0.0.6 | lib/forge-cli/route_installer.rb |