Class: Monoz::ProjectCollection
- Inherits:
-
Object
- Object
- Monoz::ProjectCollection
- Includes:
- Enumerable
- Defined in:
- lib/monoz/project_collection.rb
Instance Method Summary collapse
- #all ⇒ Object
- #exist?(name) ⇒ Boolean
- #filter(filters = []) ⇒ Object
- #find(name) ⇒ Object
-
#initialize(file_path) ⇒ ProjectCollection
constructor
A new instance of ProjectCollection.
- #order(key) ⇒ Object
- #to_table ⇒ Object
Constructor Details
#initialize(file_path) ⇒ ProjectCollection
Returns a new instance of ProjectCollection.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/monoz/project_collection.rb', line 12 def initialize(file_path) @items = [] project_folders = Monoz.folders search_paths = project_folders.map { |folder| File.join(file_path, folder) } search_paths.each do |search_path| Dir.glob(File.join(search_path, "*/Gemfile")).each do |gemfile_path| project_path = File.dirname(gemfile_path) project = Project.new(project_path) if project.valid? @items << project refresh_dependants(project) end end end end |
Instance Method Details
#all ⇒ Object
38 39 40 |
# File 'lib/monoz/project_collection.rb', line 38 def all @items end |
#exist?(name) ⇒ Boolean
30 31 32 |
# File 'lib/monoz/project_collection.rb', line 30 def exist?(name) !!find(name) end |
#filter(filters = []) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/monoz/project_collection.rb', line 54 def filter(filters = []) if filters.is_a?(String) filters = filters.split(",").map(&:strip) end if filters.empty? @items = [] return self end filtered_items = [] filters.each do |filter| if filter == "gems" filtered_items += @items.select { |i| i.type == "gem" } elsif filter == "apps" filtered_items += @items.select { |i| i.type == "app" } else project = find(filter) if project filtered_items << project else raise Monoz::Errors::StandardError.new("Invalid key: #{filter}") end end end @items = filtered_items.uniq self end |
#find(name) ⇒ Object
34 35 36 |
# File 'lib/monoz/project_collection.rb', line 34 def find(name) @items.select { |i| i.name == name }&.first end |
#order(key) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/monoz/project_collection.rb', line 42 def order(key) if key.to_sym == :name @items = order_by_name self elsif key.to_sym == :dependants @items = order_by_dependants self else raise "Invalid order key: #{key}" end end |
#to_table ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/monoz/project_collection.rb', line 81 def to_table rows = [] @items.each do |project| rows << [project.name, project.type, project.gem_name, project.frameworks.join(", "), project.dependants.join(", ")] end table = Terminal::Table.new( headings: ["Project", "Type", "Gem name", "Found Framework(s)", "Dependants"], rows: rows, style: { padding_left: 2, padding_right: 2, border_i: "o" } ) puts table end |