Class: Audrey::Node

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/audrey.rb

Overview

Audrey::Node This class defines an object that connects to the database for a single object record.

Direct Known Subclasses

Collection

Defined Under Namespace

Classes: Array, Collection, Hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p_db, opts = {}) ⇒ Node


initialize



686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/audrey.rb', line 686

def initialize(p_db, opts={})
	# param check
	if not p_db.is_a?(Audrey)
		raise 'db-param-not-audrey: ' + p_db.class.to_s
	end
	
	# db and engine
	@db = p_db
	@engine = @db.engine
	
	# hold on to flcass if one was sent
	@aclass = opts['aclass']
	
	# if a row was sent, cache it and set pk
	if opts['row']
		@row_cache = opts['row']
		@pk = @row_cache['pk']
	else
		@pk = opts['pk'] || Audrey::Util.uuid
		@row_cache = nil
	end
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



676
677
678
# File 'lib/audrey.rb', line 676

def db
  @db
end

#pkObject (readonly)

Returns the value of attribute pk.



675
676
677
# File 'lib/audrey.rb', line 675

def pk
  @pk
end

Instance Method Details

#alive?Boolean


alive?

Returns:

  • (Boolean)


766
767
768
769
# File 'lib/audrey.rb', line 766

def alive?
	# $tm.hrm
	return @engine.object_exists?(@pk)
end

#ancestorsObject


ancestors



751
752
753
754
755
756
757
# File 'lib/audrey.rb', line 751

def ancestors
	read_check()
	
	@engine.ancestors(@pk) do |row|
		yield @db.object_from_row(row)
	end
end

#delete_objectObject


delete_object



778
779
780
781
# File 'lib/audrey.rb', line 778

def delete_object
	write_check()
	return @engine.delete_object(@pk)
end

#fcoObject


fco, isolate



734
735
736
737
# File 'lib/audrey.rb', line 734

def fco
	# $tm.hrm
	return Audrey::Util.aclass_fco(row['aclass'])
end

#isolateObject



739
740
741
742
# File 'lib/audrey.rb', line 739

def isolate
	# $tm.hrm
	return Audrey::Util.aclass_isolate(row['aclass'])
end

#rowObject


row



716
717
718
719
720
721
722
723
724
725
# File 'lib/audrey.rb', line 716

def row()
	# $tm.hrm
	read_check()
	
	if not @row_cache
		@row_cache = @engine.row_by_pk(@pk)
	end
	
	return @row_cache
end