Class: CQL::TagFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/cql/filters.rb

Overview

Not a part of the public API. Subject to change at any time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags) ⇒ TagFilter

Creates a new filter



10
11
12
# File 'lib/cql/filters.rb', line 10

def initialize tags
  @tags = tags
end

Instance Attribute Details

#tagsObject (readonly)

Tags to match



7
8
9
# File 'lib/cql/filters.rb', line 7

def tags
  @tags
end

Instance Method Details

#execute(objects, negate) ⇒ Object

Filters the input models so that only the desired ones are returned



24
25
26
27
28
# File 'lib/cql/filters.rb', line 24

def execute(objects, negate)
  method = negate ? :reject : :select

  objects.send(method) { |object| has_tags?(object, tags) }
end

#has_tags?(object, target_tags) ⇒ Boolean

Returns whether or not the object has the target tags

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/cql/filters.rb', line 15

def has_tags?(object, target_tags)
  target_tags.all? { |target_tag|
    tags = object.tags
    tags = tags.collect { |tag| tag.name } unless Gem.loaded_specs['cuke_modeler'].version.version[/^0/]
    tags.include?(target_tag)
  }
end