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

Version Path
lookbook-2.3.4 lib/lookbook/services/list_resolver.rb
lookbook-2.3.3 lib/lookbook/services/list_resolver.rb
lookbook-2.3.2 lib/lookbook/services/list_resolver.rb
lookbook-2.3.0 lib/lookbook/services/list_resolver.rb
lookbook-2.2.2 lib/lookbook/services/list_resolver.rb
lookbook-2.2.1 lib/lookbook/services/list_resolver.rb
lookbook-2.2.0 lib/lookbook/services/list_resolver.rb
lookbook-2.1.1 lib/lookbook/services/list_resolver.rb
lookbook-2.1.0 lib/lookbook/services/list_resolver.rb
lookbook-2.0.5 lib/lookbook/services/list_resolver.rb
lookbook-2.0.4 lib/lookbook/services/list_resolver.rb
lookbook-2.0.3 lib/lookbook/services/list_resolver.rb
lookbook-2.0.2 lib/lookbook/services/list_resolver.rb
lookbook-2.0.1 lib/lookbook/services/list_resolver.rb
lookbook-2.0.0 lib/lookbook/services/list_resolver.rb
lookbook-2.0.0.rc.3 lib/lookbook/services/list_resolver.rb
lookbook-2.0.0.rc.2 lib/lookbook/services/list_resolver.rb
lookbook-2.0.0.rc.1 lib/lookbook/services/list_resolver.rb
lookbook-2.0.0.beta.9 lib/lookbook/services/list_resolver.rb
lookbook-2.0.0.beta.8 lib/lookbook/services/list_resolver.rb