Class: BravoModel::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Utils, Validation
Defined in:
lib/bravo_model/base.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#debug, #full_errors

Class Method Details

.column(name, sql_type = nil, default = nil, null = true) ⇒ Object

changed columns() to a class_attribute so subclasses can inherit columns



13
14
15
# File 'lib/bravo_model/base.rb', line 13

def self.column(name, sql_type = nil, default = nil, null = true)
  self.columns += [ActiveRecord::ConnectionAdapters::Column.new( name.to_s, default, sql_type.to_s, null )]
end

.column_defaultsObject



25
26
27
28
29
# File 'lib/bravo_model/base.rb', line 25

def self.column_defaults
  Hash[self.columns.map{ |col|
    [col.name, col.default]
  }]
end

.columns_hashObject



17
18
19
20
21
22
23
# File 'lib/bravo_model/base.rb', line 17

def self.columns_hash
  h = {}
  for c in self.columns
    h[c.name] = c
  end
  return h
end

.descends_from_active_record?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/bravo_model/base.rb', line 32

def self.descends_from_active_record?
  return true
end

Instance Method Details

#createObject

nodoc



41
42
43
44
45
46
# File 'lib/bravo_model/base.rb', line 41

def create
  run_callbacks :create do
    @new_record = false
    self.id = SecureRandom.uuid
  end
end

#persisted?Boolean

nodoc

Returns:

  • (Boolean)


50
51
52
# File 'lib/bravo_model/base.rb', line 50

def persisted?
  id.present?
end

#updateObject

nodoc



56
57
58
59
60
# File 'lib/bravo_model/base.rb', line 56

def update
  run_callbacks :update do
    true
  end
end