class Dbee::Model
In DB terms, a Model
is usually a table, but it does not have to be. You can also re-model your DB schema using Dbee::Models.
Attributes
constraints[R]
filters[R]
models_by_name[R]
name[R]
partitioners[R]
relationships[R]
table[R]
Public Class Methods
new( name:, constraints: [], relationships: [], models: [], partitioners: [], table: '' )
click to toggle source
# File lib/dbee/model.rb, line 32 def initialize( name:, constraints: [], # Exists here for tree based model backward compatibility. relationships: [], models: [], # Exists here for tree based model backward compatibility. partitioners: [], table: '' ) @name = name @constraints = Constraints.array(constraints || []).uniq @relationships = Relationships.make_keyed_by(:name, relationships) @models_by_name = name_hash(Model.array(models)) @partitioners = Partitioner.array(partitioners).uniq @table = table.to_s.empty? ? @name : table.to_s ensure_input_is_valid freeze end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/dbee/model.rb, line 62 def <=>(other) name <=> other.name end
==(other)
click to toggle source
# File lib/dbee/model.rb, line 56 def ==(other) other.instance_of?(self.class) && other.name == name && other.table == table && children_are_equal(other) end
Also aliased as: eql?
hash()
click to toggle source
# File lib/dbee/model.rb, line 66 def hash [ name.hash, table.hash, relationships.hash, sorted_constraints.hash, sorted_partitioners.hash, sorted_models.hash ].hash end
relationship_for_name(relationship_name)
click to toggle source
# File lib/dbee/model.rb, line 52 def relationship_for_name(relationship_name) relationships[relationship_name] end
to_s()
click to toggle source
# File lib/dbee/model.rb, line 77 def to_s name end
Private Instance Methods
children_are_equal(other)
click to toggle source
# File lib/dbee/model.rb, line 89 def children_are_equal(other) other.relationships == relationships && other.sorted_constraints == sorted_constraints && other.sorted_partitioners == sorted_partitioners && other.sorted_models == sorted_models end
ensure_input_is_valid()
click to toggle source
# File lib/dbee/model.rb, line 96 def ensure_input_is_valid raise ArgumentError, 'name is required' if name.to_s.empty? constraints&.any? && relationships&.any? && \ raise(ArgumentError, 'constraints and relationships are mutually exclusive') end
name_hash(array)
click to toggle source
# File lib/dbee/model.rb, line 85 def name_hash(array) array.map { |a| [a.name, a] }.to_h end