Module: MiddlewareCli::App

Included in:
ExtractMiddleware, Formatter, List
Defined in:
lib/middleware-cli/app.rb

Constant Summary collapse

APPLICATION_ROUTE =
"::Application.routes"

Instance Method Summary collapse

Instance Method Details

#app_pathObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/middleware-cli/app.rb', line 6

def app_path
  path_array = Dir.getwd.split("/")
  while not path_array.empty?
    guess_path = path_array.join("/")
    unless Dir[guess_path + "/Gemfile"].empty?
      return guess_path
    end
    path_array.pop
  end
  Dir.getwd
end

#copy_file(path, directory_path) ⇒ Object



36
37
38
39
# File 'lib/middleware-cli/app.rb', line 36

def copy_file(path, directory_path)
  FileUtils.mkdir_p directory_path unless Dir.exists?(directory_path)
  FileUtils.cp path, directory_path
end

#filtered_listObject



24
25
26
27
28
29
30
# File 'lib/middleware-cli/app.rb', line 24

def filtered_list
  `rake middleware`.each_line.map do |middleware|
    if middleware.start_with?("use") || middleware.start_with?("run")
      middleware.split(" ").last
    end
  end.compact
end

#is_route_middleware?(middleware) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/middleware-cli/app.rb', line 41

def is_route_middleware?(middleware)
  middleware.include?(APPLICATION_ROUTE)
end

#load_applicationObject



32
33
34
# File 'lib/middleware-cli/app.rb', line 32

def load_application
  require "#{app_path}/config/environment"
end

#middleware_listObject



18
19
20
21
22
# File 'lib/middleware-cli/app.rb', line 18

def middleware_list
  filtered_list.each_with_index do |middleware, index|
    yield(middleware, index + 1)
  end
end

#relative_app_path(*paths) ⇒ Object



45
46
47
# File 'lib/middleware-cli/app.rb', line 45

def relative_app_path(*paths)
  [app_path, paths].join('/')
end