Module: Klastera::Concerns::Cluster::ClassMethods

Defined in:
app/models/klastera/concerns/cluster.rb

Instance Method Summary collapse

Instance Method Details

#modes_as_stringsObject



78
79
80
# File 'app/models/klastera/concerns/cluster.rb', line 78

def modes_as_strings
  ::Cluster::MODES.map{|m|m.to_s}
end


62
63
64
65
66
# File 'app/models/klastera/concerns/cluster.rb', line 62

def related_entities(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)
  related_entities(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