Module: FatFreeCRM::Fields::InstanceMethods

Defined in:
lib/fat_free_crm/fields.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fat_free_crm/fields.rb', line 68

def method_missing(method_id, *args, &block)
  if method_id.to_s =~ /^cf_/
    # Refresh columns and try again.
    self.class.reset_column_information
    # If new record, create new object from class, else reload class
    object = self.new_record? ? self.class.new : (self.reload && self)
    # ensure serialization is setup if needed
    self.class.serialize_custom_fields!
    # Try again if object now responds to method, else return nil
    object.respond_to?(method_id) ? object.send(method_id, *args) : nil
  else
    super
  end
end

Instance Method Details

#assign_attributes(new_attributes, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/fat_free_crm/fields.rb', line 59

def assign_attributes(new_attributes, options = {})
  super
# If attribute is unknown, a new custom field may have been added.
# Refresh columns and try again.
rescue ActiveRecord::UnknownAttributeError
  self.class.reset_column_information
  super
end

#custom_fields_validatorObject

run custom field validations on this object




55
56
57
# File 'lib/fat_free_crm/fields.rb', line 55

def custom_fields_validator
  self.field_groups.map(&:fields).flatten.each{|f| f.custom_validator(self) }
end

#field_groupsObject



48
49
50
51
# File 'lib/fat_free_crm/fields.rb', line 48

def field_groups
  field_groups = self.class.field_groups
  respond_to?(:tag_ids) ? field_groups.with_tags(tag_ids) : field_groups
end