Class: Sidekiq::Tasks::Set

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/sidekiq/tasks/set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects) ⇒ Set

Returns a new instance of Set.



23
24
25
# File 'lib/sidekiq/tasks/set.rb', line 23

def initialize(objects)
  @objects = objects
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



21
22
23
# File 'lib/sidekiq/tasks/set.rb', line 21

def objects
  @objects
end

Class Method Details

.match?(object, attributes) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
# File 'lib/sidekiq/tasks/set.rb', line 10

def self.match?(object, attributes)
  attributes.any? do |attribute, value|
    next true if [nil, ""].include?(value)

    object_value = object.public_send(attribute).to_s.downcase.gsub(/[^a-z0-9]/, "")
    search_fragments = value.to_s.downcase.gsub(/[^a-z0-9\s]/, "").split

    search_fragments.all? { |fragment| object_value.include?(fragment) }
  end
end

Instance Method Details

#find_by(name: nil) ⇒ Object



31
32
33
# File 'lib/sidekiq/tasks/set.rb', line 31

def find_by(name: nil)
  where(name: name).first
end

#find_by!(name: nil) ⇒ Object



35
36
37
# File 'lib/sidekiq/tasks/set.rb', line 35

def find_by!(name: nil)
  find_by(name: name) || raise(NotFoundError, "'#{name}' not found")
end

#where(attributes = {}) ⇒ Object



27
28
29
# File 'lib/sidekiq/tasks/set.rb', line 27

def where(attributes = {})
  reflect(objects.select { |object| self.class.match?(object, attributes) })
end