Class: RSpec::Core::FilterableItemRepository::UpdateOptimized

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/metadata_filter.rb

Overview

This implementation is simple, and is optimized for frequent updates but rare queries. `append` and `prepend` do no extra processing, and no internal memoization is done, since this is not optimized for queries.

This is ideal for use by a example or example group, which may be updated multiple times with globally configured hooks, etc, but will not be queried frequently by other examples or examle groups.

Direct Known Subclasses

QueryOptimized

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(applies_predicate) ⇒ UpdateOptimized

Returns a new instance of UpdateOptimized.


101
102
103
104
# File 'lib/rspec/core/metadata_filter.rb', line 101

def initialize(applies_predicate)
  @applies_predicate = applies_predicate
  @items_and_filters = []
end

Instance Attribute Details

#items_and_filtersObject (readonly)

Returns the value of attribute items_and_filters


99
100
101
# File 'lib/rspec/core/metadata_filter.rb', line 99

def items_and_filters
  @items_and_filters
end

Instance Method Details

#append(item, metadata) ⇒ Object


106
107
108
# File 'lib/rspec/core/metadata_filter.rb', line 106

def append(item, )
  @items_and_filters << [item, ]
end

#delete(item, metadata) ⇒ Object


114
115
116
# File 'lib/rspec/core/metadata_filter.rb', line 114

def delete(item, )
  @items_and_filters.delete [item, ]
end

#items_for(request_meta) ⇒ Object


118
119
120
121
122
123
# File 'lib/rspec/core/metadata_filter.rb', line 118

def items_for(request_meta)
  @items_and_filters.each_with_object([]) do |(item, item_meta), to_return|
    to_return << item if item_meta.empty? ||
                         MetadataFilter.apply?(@applies_predicate, item_meta, request_meta)
  end
end

#prepend(item, metadata) ⇒ Object


110
111
112
# File 'lib/rspec/core/metadata_filter.rb', line 110

def prepend(item, )
  @items_and_filters.unshift [item, ]
end