Module: Rhubarb::Persisting
- Defined in:
- lib/rhubarb/rhubarb.rb
Class Method Summary collapse
Instance Method Summary collapse
- #db ⇒ Object
-
#delete ⇒ Object
Deletes the row corresponding to this object from the database; invalidates =self= and any other objects backed by this row.
-
#deleted? ⇒ Boolean
Returns true if the row backing this object has been deleted from the database.
-
#initialize(tup) ⇒ Object
Initializes a new instance backed by a tuple of values.
Class Method Details
.included(other) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/rhubarb/rhubarb.rb', line 438 def self.included(other) class << other include PersistingClassMixins end other.class_eval do attr_reader :row_id attr_reader :created attr_reader :updated end end |
Instance Method Details
#db ⇒ Object
450 451 452 |
# File 'lib/rhubarb/rhubarb.rb', line 450 def db self.class.db end |
#delete ⇒ Object
Deletes the row corresponding to this object from the database; invalidates =self= and any other objects backed by this row
476 477 478 479 480 481 |
# File 'lib/rhubarb/rhubarb.rb', line 476 def delete self.db.execute("delete from #{self.class.table_name} where row_id = ?", @row_id) mark_dirty @tuple = nil @row_id = nil end |
#deleted? ⇒ Boolean
Returns true if the row backing this object has been deleted from the database
455 456 457 458 |
# File 'lib/rhubarb/rhubarb.rb', line 455 def deleted? freshen not @tuple end |
#initialize(tup) ⇒ Object
Initializes a new instance backed by a tuple of values. Do not call this directly. Create new instances with the create or find methods.
462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/rhubarb/rhubarb.rb', line 462 def initialize(tup) @backed = true @tuple = tup mark_fresh @row_id = @tuple["row_id"] @created = @tuple["created"] @updated = @tuple["updated"] resolve_referents self.class.dirtied[@row_id] ||= @expired_after self end |