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



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/base_properties.rb', line 41

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



25
26
27
28
29
# File 'lib/base_properties.rb', line 25

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

#default_attributesObject

Default attributes support



56
57
58
# File 'lib/base_properties.rb', line 56

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

#set_attribute_defaultsObject

:nodoc:



60
61
62
63
64
# File 'lib/base_properties.rb', line 60

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
# 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} >"
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



33
34
35
36
37
# File 'lib/base_properties.rb', line 33

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