Class: Dbee::Model::Partitioner
- Inherits:
-
Object
- Object
- Dbee::Model::Partitioner
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(name: '', value: nil) ⇒ Partitioner
constructor
A new instance of Partitioner.
Constructor Details
#initialize(name: '', value: nil) ⇒ Partitioner
Returns a new instance of Partitioner.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/dbee/model/partitioner.rb', line 19 def name @name end |
#value ⇒ Object (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 |
#hash ⇒ Object
32 33 34 |
# File 'lib/dbee/model/partitioner.rb', line 32 def hash "#{name}#{value}".hash end |