Module: ActiveOrient::BaseProperties

Extended by:
ActiveSupport::Concern
Included in:
Model
Defined in:
lib/base_properties.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Default Model comparison



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/base_properties.rb', line 53

def == other  # :nodoc:
  case other
  when String # Probably a link or a rid
    "##{rid}" == other || rid == other
  when  ActiveOrient::Model
   rid == other.rid
  else
    content_attributes.keys.inject(true){ |res, key|
      res && other.respond_to?(key) && (send(key) == other.send(key))
    }
  end
end

#content_attributesObject

Comparison support



27
28
29
30
31
32
# File 'lib/base_properties.rb', line 27

def content_attributes  # :nodoc:
#      HashWithIndifferentAccess[attributes.reject do |(attr, _)|
  Hash[attributes.reject do |(attr, _)|
    attr.to_s =~ /(_count)\z/ || attr.to_s =~ /^in_/ || attr.to_s =~ /^out_/ || [:created_at, :updated_at, :type, :id, :order_id, :contract_id].include?(attr.to_sym)
  end]
end

#default_attributesObject

Default attributes support



68
69
70
71
# File 'lib/base_properties.rb', line 68

def default_attributes
			{}
  #{:created_at => DateTime.now }
end

#embeddedObject

used by Model.to_or



36
37
38
39
40
41
# File 'lib/base_properties.rb', line 36

def embedded
	{ "@type" => 'd', "@class" => self.class.ref_name }
	            .merge(content_attributes)
	            .map{|y,x| z='';  z  <<  y.to_s << ': ' << x.to_or.to_s }.join(' ,')
	
end

#set_attribute_defaultsObject

:nodoc:



73
74
75
76
77
# File 'lib/base_properties.rb', line 73

def set_attribute_defaults # :nodoc:
  default_attributes.each do |key, val|
    self.send("#{key}=", val) if self.send(key).nil?
  end
end

#to_humanObject

Default presentation of ActiveOrient::Model-Objects



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/base_properties.rb', line 11

def to_human
	"<#{self.class.to_s.demodulize}: " + content_attributes.map do |attr, value|
		v= case value
			 when ActiveOrient::Model
				 "< #{self.class.to_.demodulize} : #{value.rrid} >"
			 when OrientSupport::Array
				 value.rrid #.to_human #.map(&:to_human).join("::")
			 else
				 value.from_orient
			 end
		"%s : %s" % [ attr, v]  unless v.nil?
	end.compact.sort.join(', ') + ">".gsub('"' , ' ')
end

#update_missing(attrs) ⇒ Object

Update nil attributes from given Hash or model



45
46
47
48
49
# File 'lib/base_properties.rb', line 45

def update_missing attrs  # :nodoc:
  attrs = attrs.content_attributes unless attrs.kind_of?(Hash)
  attrs.each{|attr, val| send "#{attr}=", val if send(attr).blank?}
  self # for chaining
end