Class: Sidekiq::Tasks::Set
- Inherits:
-
Object
- Object
- Sidekiq::Tasks::Set
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/sidekiq/tasks/set.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Class Method Summary collapse
Instance Method Summary collapse
- #find_by(name: nil) ⇒ Object
- #find_by!(name: nil) ⇒ Object
-
#initialize(objects) ⇒ Set
constructor
A new instance of Set.
- #where(attributes = {}) ⇒ Object
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
#objects ⇒ Object (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
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 |