Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Includes:
VirtualFields, Vmdb::Logging
Defined in:
lib/extensions/ar_base.rb,
lib/extensions/ar_miq_set.rb,
lib/extensions/ar_virtual.rb,
lib/extensions/ar_paginate.rb,
lib/extensions/ar_taggable.rb,
lib/extensions/ar_number_of.rb,
lib/extensions/ar_base_model.rb,
lib/extensions/ar_column_names.rb,
lib/extensions/ar_extract_objects.rb

Direct Known Subclasses

ApplicationRecord, XmlData

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VirtualDelegates

select_from_alias, select_from_alias_table

Methods included from Vmdb::Logging

#_log

Class Method Details

.acts_as_miq_set(model_class = nil) ⇒ Object


7
8
9
10
11
# File 'lib/extensions/ar_miq_set.rb', line 7

def self.acts_as_miq_set(model_class = nil)
  include ActsAsMiqSet

  self.model_class = model_class unless model_class.nil?
end

.acts_as_miq_set_memberObject


3
4
5
# File 'lib/extensions/ar_miq_set.rb', line 3

def self.acts_as_miq_set_member
  include ActsAsMiqSetMember
end

.acts_as_miq_taggableObject


3
4
5
6
7
# File 'lib/extensions/ar_taggable.rb', line 3

def self.acts_as_miq_taggable
  has_many :taggings, :as => :taggable, :dependent => :destroy
  has_many :tags, :through => :taggings
  include ActsAsTaggable
end

.column_names_symbolsObject


3
4
5
# File 'lib/extensions/ar_column_names.rb', line 3

def self.column_names_symbols
  @column_names_symbols ||= column_names.collect(&:to_sym)
end

.extract_ids(*objects) ⇒ Object


10
11
12
13
14
15
# File 'lib/extensions/ar_extract_objects.rb', line 10

def self.extract_ids(*objects)
  is_array = objects.length > 1 || objects.first.kind_of?(Array)
  objects = objects.flatten
  ret = objects.first.kind_of?(self) ? objects.collect(&:id) : objects
  is_array ? ret : ret.first
end

.extract_objects(*objects) ⇒ Object


3
4
5
6
7
8
# File 'lib/extensions/ar_extract_objects.rb', line 3

def self.extract_objects(*objects)
  is_array = objects.length > 1 || objects.first.kind_of?(Array)
  objects = objects.flatten
  ret = objects.first.kind_of?(Integer) ? where(:id => objects) : objects
  is_array ? ret : ret.first
end

.model_suffixObject


6
7
8
# File 'lib/extensions/ar_base_model.rb', line 6

def model_suffix
  name[base_model.name.length..-1]
end

.paginate(req_offset, req_limit) ⇒ Object

Used by the REST API


6
7
8
# File 'lib/extensions/ar_paginate.rb', line 6

def self.paginate(req_offset, req_limit)
  offset(req_offset).limit(req_limit)
end

.truncateObject

Truncates the table.

Example

Post.truncate

10
11
12
# File 'lib/extensions/ar_base.rb', line 10

def self.truncate
  connection.truncate(table_name, "#{name} Truncate")
end

Instance Method Details

#number_of(assoc) ⇒ Object


3
4
5
6
# File 'lib/extensions/ar_number_of.rb', line 3

def number_of(assoc)
  @number_of ||= {}
  @number_of[assoc.to_sym] ||= send(assoc).try!(:size) || 0
end