Module: Klastera::Concerns::Cluster::ClassMethods
- Defined in:
- app/models/klastera/concerns/cluster.rb
Instance Method Summary collapse
- #modes_as_strings ⇒ Object
- #related_entities(attr_needed: :class_name, macro: :has_many) ⇒ Object
- #total_records_assign_to(cluster_instance) ⇒ Object
Instance Method Details
#modes_as_strings ⇒ Object
78 79 80 |
# File 'app/models/klastera/concerns/cluster.rb', line 78 def modes_as_strings ::Cluster::MODES.map{|m|m.to_s} end |
#related_entities(attr_needed: :class_name, macro: :has_many) ⇒ Object
62 63 64 65 66 |
# File 'app/models/klastera/concerns/cluster.rb', line 62 def (attr_needed: :class_name, macro: :has_many) ::Cluster.reflections.map do |association_name, reflection| reflection.send(attr_needed) if reflection.macro == macro end.compact end |
#total_records_assign_to(cluster_instance) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'app/models/klastera/concerns/cluster.rb', line 68 def total_records_assign_to(cluster_instance) (attr_needed: :name).inject(0) do |total, association_name| entity = cluster_instance.send(association_name) if entity.respond_to?(:cluster_id) total+=entity.where(cluster_id: cluster_instance.id).count end total end end |