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



2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
# File 'lib/audrey.rb', line 2064

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.



2056
2057
2058
# File 'lib/audrey.rb', line 2056

def auto
  @auto
end

#clssObject

Returns the value of attribute clss.



2055
2056
2057
# File 'lib/audrey.rb', line 2055

def clss
  @clss
end

#graphObject

Returns the value of attribute graph.



2058
2059
2060
# File 'lib/audrey.rb', line 2058

def graph
  @graph
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#publishObject

Returns the value of attribute publish.



2057
2058
2059
# File 'lib/audrey.rb', line 2057

def publish
  @publish
end

#readObject

Returns the value of attribute read.



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

def read
  @read
end

#requiredObject

Returns the value of attribute required.



2059
2060
2061
# File 'lib/audrey.rb', line 2059

def required
  @required
end

#writeObject

Returns the value of attribute write.



2054
2055
2056
# File 'lib/audrey.rb', line 2054

def write
  @write
end

Instance Method Details

#add_to_class(tgt) ⇒ Object


add_to_class



2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
# File 'lib/audrey.rb', line 2085

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



2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
# File 'lib/audrey.rb', line 2120

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



2170
2171
# File 'lib/audrey.rb', line 2170

def base_checks(*opts)
end

#has_checks?Boolean


has_checks?

Returns:

  • (Boolean)


2159
2160
2161
# File 'lib/audrey.rb', line 2159

def has_checks?
  return false
end

#normalize(val) ⇒ Object


normalize



2148
2149
2150
# File 'lib/audrey.rb', line 2148

def normalize(val)
  return val
end