lib/outliers/collection.rb in outliers-0.5.1 vs lib/outliers/collection.rb in outliers-0.6.0
- old
+ new
@@ -2,21 +2,21 @@
module Outliers
class Collection
include Enumerable
- include Outliers::Verifications::Shared
+ include Outliers::Verifications::Shared::Collection
attr_reader :provider
attr_accessor :targets
def self.to_human
(self.to_s.split('::') - ['Outliers', 'Resources']).map { |p| p.underscore }.join('_').downcase.gsub(/_collection$/, '')
end
def self.verifications
- Outliers::Verifications::Shared.verifications + self.resource_class.verifications
+ Outliers::Verifications::Shared::Collection.verifications + self.resource_class.verifications
end
def self.filters
[]
end
@@ -58,11 +58,11 @@
filtered_list = self.public_send "filter_#{name}", value
case action
when 'include'
logger.info "Including resources filtered by '#{name}' with value '#{value}'."
- logger.warn "No resources match filter." unless filtered_list.any?
+ logger.warn "No resources match filter." unless (filtered_list & @list).any?
@list = filtered_list & @list
when 'exclude'
logger.info "Excluding resources filtered by '#{name}' with value '#{value}'."
@list -= filtered_list
else
@@ -73,14 +73,10 @@
def verify(name, arguments=nil)
logger.debug "Verifying '#{name}'."
name += "?" unless name =~ /^.*\?$/
- unless list.any?
- return { failing_resources: [], passing_resources: [] }
- end
-
set_target_resources name if targets.any?
logger.debug "Target resources '#{list_by_key.join(', ')}'."
unless verification_exists? name
@@ -108,11 +104,11 @@
private
def verification_exists?(name)
m = resource_class.instance_methods - resource_class.class.instance_methods
- m += Outliers::Verifications::Shared.instance_methods
+ m += Outliers::Verifications::Shared::Collection.instance_methods
m -= [:source, :id, :method_missing]
m.include? name.to_sym
end
def list_by_key
@@ -147,15 +143,18 @@
failing_resources = reject do |resource|
r = send_verification resource, verification, arguments
logger.debug "Verification of resource '#{resource.id}' #{r ? 'passed' : 'failed'}."
r
end
- { failing_resources: failing_resources, passing_resources: list - failing_resources }
+ passing_resources = list - failing_resources
+ resources = []
+ resources += passing_resources.map { |r| { id: r.id, status: 0 } }
+ resources += failing_resources.map { |r| { id: r.id, status: 1 } }
+ { resources: resources, passing: failing_resources.none? }
end
def send_collection_verification(verification, arguments)
- failing_resources = send_verification(self, verification, arguments)
- { failing_resources: failing_resources, passing_resources: list - failing_resources }
+ send_verification self, verification, arguments
end
def send_verification(object, verification, arguments)
if object.method(verification).arity.zero?
unless arguments.nil?