lib/jarl/base.rb in jarl-0.7.0 vs lib/jarl/base.rb in jarl-0.8.1
- old
+ new
@@ -40,13 +40,52 @@
abort "Failed to parse application definition in file '#{jf.path}': #{e}"
end
end.flatten
end
+ # Returns list of running application instances
+ #
+ def self.application_instances
+ @application_instances ||= applications.map(&:instances).flatten
+ end
+
# Returns list of applications matching the pattern
#
- def self.find_applications_by(pattern)
- applications.select { |a| a.full_name.index(pattern) }
+ # @param patterns [nil] Match all application instances
+ # @param patterns [String] Match application instances by single pattern
+ # @param patterns [Arary<String>] Match application instances by all patterns
+ #
+ def self.find_applications_by(patterns)
+ find_application_instances_by(patterns).map(&:application).uniq
+ end
+
+ # Returns list of running application instances matching the pattern(s)
+ #
+ # @param patterns [nil] Match all application instances
+ # @param patterns [String] Match application instances by single pattern
+ # @param patterns [Arary<String>] Match application instances by all patterns
+ #
+ def self.find_application_instances_by(patterns)
+ patterns = nil if patterns && patterns.empty?
+ case patterns
+ when nil
+ application_instances
+ when String
+ application_instances.select { |i| i.full_name.index(patterns) }
+ when Array
+ application_instances.select { |i| patterns.any? { |p| i.full_name.index(p) } }
+ else
+ fail "Unexpected #{patterns.class} passed as argument to .find_application_instances_by"
+ end
+ end
+
+ #
+ #
+ def self.reload!
+ @jarl_files = nil
+ @applications = nil
+ @application_instances = nil
+ Docker.reload!
end
private
def self.load_config(filename)