Class: Audrey::Object::Custom::Field

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

Overview

Audrey::Object::Custom::Field

Direct Known Subclasses

Scalar::String::Field

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p_name) ⇒ Field


initialize



2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
# File 'lib/audrey.rb', line 2057

def initialize(p_name)
	@name = p_name
	@read = true
	@write = true
	@clss = nil
	@auto = false
	@publish = false
	@graph = false
	
	# normalize name
	@name = @name.strip
	@name = @name.gsub(/\s+/mu, ' ')
end

Instance Attribute Details

#autoObject

Returns the value of attribute auto.



2049
2050
2051
# File 'lib/audrey.rb', line 2049

def auto
  @auto
end

#clssObject

Returns the value of attribute clss.



2048
2049
2050
# File 'lib/audrey.rb', line 2048

def clss
  @clss
end

#graphObject

Returns the value of attribute graph.



2051
2052
2053
# File 'lib/audrey.rb', line 2051

def graph
  @graph
end

#nameObject

Returns the value of attribute name.



2045
2046
2047
# File 'lib/audrey.rb', line 2045

def name
  @name
end

#publishObject

Returns the value of attribute publish.



2050
2051
2052
# File 'lib/audrey.rb', line 2050

def publish
  @publish
end

#readObject

Returns the value of attribute read.



2046
2047
2048
# File 'lib/audrey.rb', line 2046

def read
  @read
end

#requiredObject

Returns the value of attribute required.



2052
2053
2054
# File 'lib/audrey.rb', line 2052

def required
  @required
end

#writeObject

Returns the value of attribute write.



2047
2048
2049
# File 'lib/audrey.rb', line 2047

def write
  @write
end

Instance Method Details

#add_to_class(tgt) ⇒ Object


add_to_class



2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
# File 'lib/audrey.rb', line 2078

def add_to_class(tgt)
	# $tm.hrm
	
	# Ruby doesn't like it if we use an @ variable in the method definition
	# of another class.
	nme = @name.dup
	
	# read
	if @read
		tgt.define_method(nme) do
			return @node[nme]
		end
	end
	
	# write
	if @write
		# reference self inside the method for assigning the instance
		# variable
		me = self
		
		# definew method
		tgt.define_method("#{nme}=") do |val|
			val = me.normalize(val)
			return @node[nme] = val
		end
	end
end

#auto_add(object) ⇒ Object


auto_add



2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
# File 'lib/audrey.rb', line 2113

def auto_add(object)
	# early exit
	@auto or return
	
	# get audrey node
	node = object.audrey
	
	# init
	new_val = nil
	
	# add to node
	if Audrey::Object::Custom.descendant?(@auto)
		new_val = @auto.new('accessor'=>node.db)
	elsif @auto.is_a?(Proc)
		new_val = @auto.call(object)
	end
	
	# set new value
	node[@name] = new_val
end

#base_checks(*opts) ⇒ Object


base_checks



2163
2164
# File 'lib/audrey.rb', line 2163

def base_checks(*opts)
end

#has_checks?Boolean


has_checks?

Returns:

  • (Boolean)


2152
2153
2154
# File 'lib/audrey.rb', line 2152

def has_checks?
	return false
end

#normalize(val) ⇒ Object


normalize



2141
2142
2143
# File 'lib/audrey.rb', line 2141

def normalize(val)
	return val
end