Class: CiviCrm::FinancialType

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

Constant Summary collapse

@@_financial_type_cache =
{}

Class 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

.[](name, cache: true, create: Rails.env.development?) ⇒ Object

Raises:



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

def self.[](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