Sha256: 708d725ca3e943b66758fcf719247f56c00ea22fc3ea7fffcb94701df74588f4

Contents?: true

Size: 619 Bytes

Versions: 1

Compression:

Stored size: 619 Bytes

Contents

module CiviCrm
  class FinancialType < BaseResource
    entity :financial_type

    @@_financial_type_cache = {}

    def self.get(name, cache: true, create: Rails.env.development?)
      cache_key = name

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

      type = find_by("name" => name)
      type ||= create(name: name) if create

      if type
        @@_financial_type_cache[cache_key] = type.id if cache
        return type.id
      end

      raise Errors::NotFound.new(
        "FinancialType with name=#{name}"
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
civicrm-1.2.5 lib/civicrm/resources/financial_type.rb