Class: SchemaToScaffold::Path
- Inherits:
-
Object
- Object
- SchemaToScaffold::Path
- Defined in:
- lib/schema_to_scaffold/path.rb
Overview
Deal with the path argument
Instance Method Summary collapse
-
#check_directory ⇒ Object
Validate if a given path leads to a directory.
-
#choose ⇒ Object
Return the chosen path.
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
Constructor Details
#initialize(path) ⇒ Path
Returns a new instance of Path.
9 10 11 12 |
# File 'lib/schema_to_scaffold/path.rb', line 9 def initialize(path) @search_path = Dir.pwd @path = path end |
Instance Method Details
#check_directory ⇒ Object
Validate if a given path leads to a directory
16 17 18 19 20 21 22 |
# File 'lib/schema_to_scaffold/path.rb', line 16 def check_directory unless File.directory?(@search_path) puts "\nSorry #{@search_path} is not a valid directory!\nHere is an example:\nscaffold -p /home/foo/bar" exit end puts "\nLooking for schema.rb in #{@search_path}" end |
#choose ⇒ Object
Return the chosen path
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/schema_to_scaffold/path.rb', line 27 def choose search_rb if @schema_paths.empty? puts "\nSorry there is none /schema[^\/]*.rb$/ in the directory #{@search_path}" exit end @schema_paths.each_with_index {|path,indx| puts "#{indx}. #{path}" } begin print "\nSelect a path to the target schema: " end while @schema_paths[(id = gets.to_i)].nil? @schema_paths[id] end |