Method: ActiveOrient::Base#initialize
- Defined in:
- lib/base.rb
#initialize(attributes = {}, opts = {}) ⇒ Base
If a opts hash is given, keys are taken as attribute names, values as data. The model instance fields are then set automatically from the opts Hash.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/base.rb', line 50 def initialize attributes={}, opts={} logger.progname= "ActiveOrient::Base#initialize" #possible_link_array_candidates = link_candidates = Hash.new @metadata = HashWithIndifferentAccess.new # @edges = HashWithIndifferentAccess.new run_callbacks :initialize do # puts "initialize::attributes: #{attributes.inspect}" attributes.keys.each do | att | unless att[0] == "@" # @ identifies Metadata-attributes att = att.to_sym if att.is_a?(String) unless self.class.instance_methods.detect{|x| x == att } self.class.define_property att, nil # logger.debug { "property #{att.to_s} assigned to #{self.class.to_s}" } else # logger.info{ "property #{att.to_s} NOT assigned " } end end end if attributes['@type'] == 'd' # document @metadata[ :type ] = attributes.delete '@type' @metadata[ :class ] = attributes.delete '@class' @metadata[ :version ] = attributes.delete '@version' @metadata[ :fieldTypes ] = attributes.delete '@fieldTypes' if attributes.has_key?( '@rid' ) rid = attributes.delete '@rid' cluster, record = rid[1,rid.size].split(':') @metadata[ :cluster ] = cluster.to_i @metadata[ :record ] = record.to_i end #### edges -- remove in_ and out_ and de-capitalize the remaining edge if @metadata[ :fieldTypes ].present? && (@metadata[ :fieldTypes ] =~ /=g/) edges = @metadata['fieldTypes'].split(',').find_all{|x| x=~/=g/}.map{|x| x.split('=').first} edges.each do |edge| operator, *base_edge = edge.split('_') base_edge = base_edge.join('_') unless self.class.instance_methods.detect{|x| x == base_edge } ## define two methods: out_{Edge}/{in_Edge} -> edge. self.class.define_property base_edge, nil self.class.send :alias_method, base_edge.underscore, edge # # logger.debug { "#{link}:: edge #{edge} assigned to #{self.class.to_s} and remaped to #{base_edge.underscore}" } end end end end self.attributes = attributes # set_attribute_defaults is now after_init callback end ActiveOrient::Base.store_riid self end |