Sha256: 9e6828493edf1f4a99dbd05b3071ff76f6484e179a0fcebe8879d29b9efac1db

Contents?: true

Size: 782 Bytes

Versions: 2

Compression:

Stored size: 782 Bytes

Contents

module CiviCrm
  class CustomField < BaseResource
    entity :custom_field

    @@_custom_field_cache = {}

    def self.[](entity, field, cache: true)
      cache_key = name

      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=#{name}"
      )
    end

    def key
      "custom_#{id}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
civicrm-1.3.3 lib/civicrm/resources/custom_field.rb
civicrm-1.3.2 lib/civicrm/resources/custom_field.rb