Class: Dbee::Model::Partitioner

Inherits:
Object
  • Object
show all
Defined in:
lib/dbee/model/partitioner.rb

Overview

An Partitioner is a way to explicitly define constraints on a model. For example, say we want to create a data model, but restrict the returned data to a subset based on a ‘type’ column like ActiveRecord does for Single Table Inheritance. We could use a partition to define this constraint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: '', value: nil) ⇒ Partitioner

Returns a new instance of Partitioner.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
# File 'lib/dbee/model/partitioner.rb', line 21

def initialize(name: '', value: nil)
  raise ArgumentError, 'name is required' if name.to_s.empty?

  @name   = name.to_s
  @value  = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/dbee/model/partitioner.rb', line 19

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/dbee/model/partitioner.rb', line 19

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/dbee/model/partitioner.rb', line 28

def <=>(other)
  "#{name}#{value}" <=> "#{other.name}#{other.value}"
end

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



36
37
38
39
40
# File 'lib/dbee/model/partitioner.rb', line 36

def ==(other)
  other.instance_of?(self.class) &&
    other.name == name &&
    other.value == value
end

#hashObject



32
33
34
# File 'lib/dbee/model/partitioner.rb', line 32

def hash
  "#{name}#{value}".hash
end