Class: BravoModel::Base
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BravoModel::Base
- Includes:
- Utils, Validation
- Defined in:
- lib/bravo_model/base.rb
Overview
based on gist.github.com/1101257
Class Method Summary collapse
-
.column(name, sql_type = nil, default = nil, null = true) ⇒ Object
changed columns() to a class_attribute so subclasses can inherit columns.
- .column_defaults ⇒ Object
- .columns_hash ⇒ Object
- .descends_from_active_record? ⇒ Boolean
Instance Method Summary collapse
-
#create ⇒ Object
nodoc.
-
#persisted? ⇒ Boolean
nodoc.
-
#update ⇒ Object
nodoc.
Methods included from Utils
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_defaults ⇒ Object
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_hash ⇒ Object
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
32 33 34 |
# File 'lib/bravo_model/base.rb', line 32 def self.descends_from_active_record? return true end |
Instance Method Details
#create ⇒ Object
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
50 51 52 |
# File 'lib/bravo_model/base.rb', line 50 def persisted? id.present? end |
#update ⇒ Object
nodoc
56 57 58 59 60 |
# File 'lib/bravo_model/base.rb', line 56 def update run_callbacks :update do true end end |