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

bclass, node_class

Methods inherited from Audrey::Object

descendants, fclasses, fco, inherited, isolate

Constructor Details

#initialize(opts = {}) ⇒ Custom


initialize



1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
# File 'lib/audrey.rb', line 1800

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)


1890
1891
1892
1893
1894
1895
1896
# File 'lib/audrey.rb', line 1890

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



1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
# File 'lib/audrey.rb', line 1866

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)


1926
1927
1928
1929
1930
1931
1932
1933
1934
# File 'lib/audrey.rb', line 1926

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



1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
# File 'lib/audrey.rb', line 1905

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



1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
# File 'lib/audrey.rb', line 1847

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



1836
1837
1838
# File 'lib/audrey.rb', line 1836

def audrey
	return @node
end