class SchemaToScaffold::Path
Deal with the path argument
Public Class Methods
new(path)
click to toggle source
# File lib/schema_to_scaffold/path.rb, line 8 def initialize(path) @path = path || Dir.pwd end
Public Instance Methods
choose()
click to toggle source
Return the chosen path
# File lib/schema_to_scaffold/path.rb, line 14 def choose validate_path search_paths_list = search_paths if search_paths_list.empty? puts "\nThere is no /schema[^\/]*.rb$/ in the directory #{@path}" exit end search_paths_list.each_with_index {|path,indx| puts "#{indx}. #{path}" } begin print "\nSelect a path to the target schema: " end while search_paths_list[(id = STDIN.gets.to_i)].nil? search_paths_list[id] end
Private Instance Methods
search_paths()
click to toggle source
Will search for /schema*.rb$/ in the current directory
# File lib/schema_to_scaffold/path.rb, line 45 def search_paths result = [] Find.find(@path) do |s_p| result << s_p if s_p[/schema[^\/]*.rb$/] end result end
validate_path()
click to toggle source
Validate if a given path leads to a directory
# File lib/schema_to_scaffold/path.rb, line 34 def validate_path if File.directory?(@path.to_s) puts "\nLooking for schema.rb in #{@path}" else puts "\nSorry #{@path} is not a valid directory!\nHere is an example:\nscaffold -p /home/foo/bar" exit end end