Class: Prj::App
- Inherits:
-
Object
- Object
- Prj::App
- Defined in:
- lib/prj/app.rb
Class Attribute Summary collapse
-
.default_projects_root ⇒ Object
Returns the value of attribute default_projects_root.
-
.ignore_config ⇒ Object
Returns the value of attribute ignore_config.
Instance Method Summary collapse
-
#initialize(sink, args = []) ⇒ App
constructor
A new instance of App.
- #projects_root ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(sink, args = []) ⇒ App
Returns a new instance of App.
12 13 14 15 |
# File 'lib/prj/app.rb', line 12 def initialize(sink, args = []) @letters = String(args.first).each_char.to_a @sink = sink end |
Class Attribute Details
.default_projects_root ⇒ Object
Returns the value of attribute default_projects_root.
7 8 9 |
# File 'lib/prj/app.rb', line 7 def default_projects_root @default_projects_root end |
.ignore_config ⇒ Object
Returns the value of attribute ignore_config.
7 8 9 |
# File 'lib/prj/app.rb', line 7 def ignore_config @ignore_config end |
Instance Method Details
#projects_root ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/prj/app.rb', line 35 def projects_root @projects_root ||= begin path = begin raise "default config" if self.class.ignore_config File.read(File.("~/.prj")).chomp rescue self.class.default_projects_root end File.(path).freeze end end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/prj/app.rb', line 17 def run if @letters.empty? @sink.puts projects_root else finder = Finder.new(projects_root) filter = Filter.new(@letters) directories = finder.find_project_directories filtered_directories = filter.filter(directories) target_directory = File.join(projects_root, filtered_directories.first.to_s) @sink.puts target_directory end return 0 end |