Class: FrozenRecord::Scope::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/frozen_record/scope.rb

Direct Known Subclasses

CoverMatcher, IncludeMatcher

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Matcher

Returns a new instance of Matcher.



309
310
311
# File 'lib/frozen_record/scope.rb', line 309

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



303
304
305
# File 'lib/frozen_record/scope.rb', line 303

def value
  @value
end

Class Method Details

.for(value) ⇒ Object



291
292
293
294
295
296
297
298
299
300
# File 'lib/frozen_record/scope.rb', line 291

def for(value)
  case value
  when Array
    IncludeMatcher.new(value)
  when Range
    CoverMatcher.new(value)
  else
    new(value)
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



321
322
323
# File 'lib/frozen_record/scope.rb', line 321

def ==(other)
  self.class == other.class && value == other.value
end

#hashObject



305
306
307
# File 'lib/frozen_record/scope.rb', line 305

def hash
  self.class.hash ^ value.hash
end

#match?(other) ⇒ Boolean

Returns:

  • (Boolean)


317
318
319
# File 'lib/frozen_record/scope.rb', line 317

def match?(other)
  @value == other
end

#ranged?Boolean

Returns:

  • (Boolean)


313
314
315
# File 'lib/frozen_record/scope.rb', line 313

def ranged?
  false
end