Class: Audrey::Object::Custom

Inherits:
Hash show all
Extended by:
Searchable
Defined in:
lib/audrey.rb

Overview

Audrey::Object::Custom

Direct Known Subclasses

Graph

Defined Under Namespace

Classes: Field, Graph

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Searchable

count, each, first, sample, samples

Methods inherited from Hash

hsa, node_class

Methods inherited from Audrey::Object

aclasses, descendants, fco, inherited, isolate

Constructor Details

#initialize(opts = {}) ⇒ Custom


initialize



1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
# File 'lib/audrey.rb', line 1793

def initialize(opts={})
	# If a node is passed as an option, use that node and don't create a
	# new object.
	if @node = opts['node']
		if block_given?
			@node.db.transaction() do |tr|
				yield self
				tr.commit
			end
		end
	
	# If no node is passed, create a new object. If a block is given, run
	# that block within a transaction.
	else
		db = Audrey.explicit_or_current_db(opts['accessor'])
		
		# if within block
		if block_given?
			db.transaction() do |tr|
				within_initialize db, opts
				yield self
				tr.commit
			end
		else
			within_initialize db, opts
		end
	end
end

Class Method Details

.descendant?(object) ⇒ Boolean


descendant?

Returns:

  • (Boolean)


1883
1884
1885
1886
1887
1888
1889
# File 'lib/audrey.rb', line 1883

def self.descendant?(object)
	if object.is_a?(Class)
		return object < Audrey::Object::Custom
	else
		return object.class < Audrey::Object::Custom
	end
end

.fieldsObject


fields



1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
# File 'lib/audrey.rb', line 1859

def self.fields
	# $tm.hrm
	
	# get superclass fields
	if self.superclass.respond_to?('fields')
		rv = self.superclass.fields()
	else
		rv = {}
	end
	
	# get own fields
	rv = rv.merge(own_fields())
	
	# return
	return rv
end

.has_checks?Boolean


has_checks?

Returns:

  • (Boolean)


1919
1920
1921
1922
1923
1924
1925
1926
1927
# File 'lib/audrey.rb', line 1919

def self.has_checks?
	# cache return value
	if not instance_variable_defined?(:@has_checks_cache)
		@has_checks_cache = has_checks_search()
	end
	
	# return
	return @has_checks_cache
end

.new_auto_fields(object) ⇒ Object


new_auto_fields



1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
# File 'lib/audrey.rb', line 1898

def self.new_auto_fields(object)
	# $tm.hrm
	
	# loop through fields
	fields.each do |name, dfn|
		dfn.auto_add object
	end
	
	# rescurse to super class
	unless self == Audrey::Object::Custom
		self.superclass.new_auto_fields(object)
	end
end

.own_fieldsObject


own_fields



1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
# File 'lib/audrey.rb', line 1840

def self.own_fields
	# $tm.hrm
	
	# ensure @own_fields exists
	if not instance_variable_defined?(:@own_fields)
		@own_fields = {}
	end
	
	# return
	return @own_fields
end

Instance Method Details

#audreyObject


audrey



1829
1830
1831
# File 'lib/audrey.rb', line 1829

def audrey
	return @node
end