Class: CiviCrm::CustomField

Inherits:
BaseResource show all
Defined in:
lib/civicrm/resources/custom_field.rb

Constant Summary collapse

@@_custom_field_cache =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions::Destroy

#delete, #delete!

Methods included from Actions::Update

#save, #update

Methods included from Actions::Create

included

Methods included from Actions::Find

included

Methods included from Actions::List

included

Methods inherited from Resource

#as_json, #attribute, #attributes, build_from, entity, entity_class_name, #initialize, #inspect, #method_missing, #refresh_from, #to_hash, #to_json, #to_s

Constructor Details

This class inherits a constructor from CiviCrm::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CiviCrm::Resource

Class Method Details

.[](entity, field, cache: true) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/civicrm/resources/custom_field.rb', line 7

def self.[](entity, field, cache: true)
  cache_key = [entity.underscore, field].join("/")

  if cache && @@_custom_field_cache.key?(cache_key)
    return @@_custom_field_cache[cache_key]
  end

  field = find_by(
    "custom_group_id.extends" => entity,
    "custom_group_id.name" => entity,
    "name" => field,
    "options" => { "or" => [["custom_group_id.extends", "custom_group_id.name"]] }
  )

  if field
    @@_custom_field_cache[cache_key] = field if cache
    return field
  end

  raise Errors::NotFound.new(
    "CustomField of #{entity} with name=#{field}"
  )
end

Instance Method Details

#keyObject



31
32
33
# File 'lib/civicrm/resources/custom_field.rb', line 31

def key
  "custom_#{id}"
end