Class: SchemaToScaffold::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_to_scaffold/path.rb

Overview

Deal with the path argument

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Path

Returns a new instance of Path.



8
9
10
# File 'lib/schema_to_scaffold/path.rb', line 8

def initialize(path)
  @path = path || Dir.pwd
end

Instance Method Details

#chooseObject

Return the chosen path



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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: "
    while search_paths_list[(id = STDIN.gets.to_i)].nil?; end
  rescue Interrupt => e
    exit 1
  end 


  search_paths_list[id]
end