Sha256: 4c7567ca20c44b40432f0a08c0acee052f9b0006238f18e5ef915e46849c8606
Contents?: true
Size: 807 Bytes
Versions: 28
Compression:
Stored size: 807 Bytes
Contents
module Lookbook class ListResolver < Service attr_reader :item_set def initialize(to_include = nil, item_set = nil) @to_include = to_include @item_set = Array(item_set).compact.uniq.map(&:to_s) end def call(&resolver) included = to_include.inject([]) do |result, name| if name == "*" result += item_set.select { |item| !result.include?(item) } elsif item_set.include?(name) result << name end result end resolved = resolver ? included.map { |item| resolver.call(item) } : included resolved.compact end def to_include case @to_include when true ["*"] when false [] else Array(@to_include).compact.uniq.map(&:to_s) end end end end
Version data entries
28 entries across 28 versions & 1 rubygems