class Fakecrm::CustomType

Public Class Methods

virtual_properties() click to toggle source
# File lib/fakecrm/resource/custom_type.rb, line 88
def virtual_properties
  [:custom_attributes]
end

Public Instance Methods

activity?() click to toggle source
# File lib/fakecrm/resource/custom_type.rb, line 30
def activity?
  self.kind == 'Activity'
end
custom_attributes=(custom_attributes) click to toggle source

This is neccessary because updating DM associations is BROKEN

# File lib/fakecrm/resource/custom_type.rb, line 48
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?() click to toggle source
Calls superclass method
# File lib/fakecrm/resource/custom_type.rb, line 78
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) click to toggle source

setting name for the first time also sets id

Calls superclass method
# File lib/fakecrm/resource/custom_type.rb, line 35
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_extension() click to toggle source
# File lib/fakecrm/resource/custom_type.rb, line 73
def propagate_type_extension
  ::Fakecrm.logger.debug "Installing custom attributes@ kind=#{self.kind} name=#{self.name}"
  ::Fakecrm::TypeExtender.new(self).extend!
end