Class: Polepin::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/polepin/utility.rb

Class Method Summary collapse

Class Method Details

.boolean_columns(model_class) ⇒ Object



12
13
14
# File 'lib/polepin/utility.rb', line 12

def self.boolean_columns(model_class)
  model_class.columns.select { |c| c.type == :boolean }.collect(&:name)
end

.class_belongs_to_associations(model_class) ⇒ Object



28
29
30
# File 'lib/polepin/utility.rb', line 28

def self.class_belongs_to_associations(model_class)
  associations_of_type model_class, :belongs_to
end

.class_has_many_associations(model_class) ⇒ Object



24
25
26
# File 'lib/polepin/utility.rb', line 24

def self.class_has_many_associations(model_class)
  associations_of_type model_class, :has_many
end

.model_classesObject



4
5
6
# File 'lib/polepin/utility.rb', line 4

def self.model_classes
  ActiveRecord::Base.descendants.select { |klass| klass.table_exists? }.uniq.sort_by(&:name)
end

.record_name(record) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/polepin/utility.rb', line 16

def self.record_name(record)
  if record.class.instance_methods(false).include?(:to_s)
    record.to_s
  else
    record.send %w(name title subject keyword email to_s).select { |method| record.respond_to?(method) }.first.to_sym
  end
end

.timestamp_columns(model_class) ⇒ Object



8
9
10
# File 'lib/polepin/utility.rb', line 8

def self.timestamp_columns(model_class)
  %w(created_at updated_at) & model_class.column_names
end