Class: Fakecrm::CustomType

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/fakecrm/resource/custom_type.rb,
lib/fakecrm/resource/custom_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.virtual_propertiesObject



89
90
91
# File 'lib/fakecrm/resource/custom_type.rb', line 89

def virtual_properties
  [:custom_attributes]
end

Instance Method Details

#activity?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fakecrm/resource/custom_type.rb', line 31

def activity?
  self.kind == 'Activity'
end

#custom_attributes=(custom_attributes) ⇒ Object

This is neccessary because updating DM associations is BROKEN



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fakecrm/resource/custom_type.rb', line 49

def custom_attributes=(custom_attributes)
  if custom_attributes
    existing_attributes = self.custom_attributes.all
    existing_attributes.each do |existing_attribute|
      if !(custom_attributes.find {|c| (c[:name] || c["name"]) == existing_attribute.name})
        existing_attribute.destroy
      end
    end

    custom_attributes.each do |custom_attribute|
      name = custom_attribute["name"] || custom_attribute[:name]
      c = self.custom_attributes.first(:name => name)
      if c
        c.attributes = custom_attribute
      else
        self.custom_attributes.new(custom_attribute)
      end
    end
    @dm_is_broken = true
  end
  attribute_set(:custom_attributes, self.custom_attributes)
end

#dirty_self?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
# File 'lib/fakecrm/resource/custom_type.rb', line 79

def dirty_self?
  # This forces DM to save after changing custom attributes
  # We need this for our callback
  # Did I mention that DM associations ARE BROKEN?
  @dm_is_broken || super
ensure
  @dm_is_broken = false # NOT REALLY
end

#name=(new_name) ⇒ Object

setting name for the first time also sets id



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fakecrm/resource/custom_type.rb', line 36

def name=(new_name)
  if self.id.nil?
    if self.kind == "EventContact"
      self.id = SecureRandom.hex
    else
      self.id = new_name
    end
  end

  super
end

#propagate_type_extensionObject



74
75
76
77
# File 'lib/fakecrm/resource/custom_type.rb', line 74

def propagate_type_extension
  ::Fakecrm.logger.debug "Installing custom attributes@ kind=#{self.kind} name=#{self.name}"
  ::Fakecrm::TypeExtender.new(self).extend!
end