Class: ActiveRecord::Base

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

Defined Under Namespace

Classes: EnsureNotUsedBy

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.per_pageObject


64
65
66
67
68
69
# File 'lib/core_extensions.rb', line 64

def self.per_page
  # defined?(Rake) prevents the failure of db:migrate for postgresql
  # don't query settings table if in rake
  return 20 if defined?(Rake)
  Setting.entries_per_page rescue 20
end

.unconfigured?Boolean


60
61
62
# File 'lib/core_extensions.rb', line 60

def self.unconfigured?
  scoped.reorder('').limit(1).pluck(self.base_class.primary_key).empty?
end

Instance Method Details

#<=>(other) ⇒ Object


9
10
11
# File 'lib/core_extensions.rb', line 9

def <=>(other)
  self.name <=> other.name
end

#id_and_typeObject


54
55
56
# File 'lib/core_extensions.rb', line 54

def id_and_type
  "#{id}-#{self.class.table_name.humanize}"
end

#update_multiple_attribute(attributes) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/core_extensions.rb', line 22

def update_multiple_attribute(attributes)
  connection.update(
    "UPDATE #{self.class.quoted_table_name} SET " +
    attributes.map{|key, value| " #{connection.quote_column_name(key.to_s)} = #{quote_value(value)} " }.join(', ') +
    "WHERE #{self.class.quoted_primary_key} = #{quote_value(id)}",
    "#{self.class.name} Attribute Update"
  )
end

#update_single_attribute(attribute, value) ⇒ Object


13
14
15
16
17
18
19
20
# File 'lib/core_extensions.rb', line 13

def update_single_attribute(attribute, value)
  connection.update(
    "UPDATE #{self.class.quoted_table_name} SET " +
    "#{connection.quote_column_name(attribute.to_s)} = #{quote_value(value)} " +
    "WHERE #{self.class.quoted_primary_key} = #{quote_value(id)}",
    "#{self.class.name} Attribute Update"
  )
end