Class: KB::PetContract
Constant Summary
collapse
- STRING_FIELDS =
%i[key plan_key product_key pet_key contract_number contract_document status
source affiliate_online affiliate_offline
conversion_utm_adgroup conversion_utm_campaign
conversion_utm_content conversion_utm_medium
conversion_utm_source conversion_utm_term
conversion_utm_adgroup_id conversion_utm_campaign_id].freeze
- DATE_FIELDS =
%i[policy_start_date policy_expiration_date].freeze
- INTEGER_FIELDS =
%i[
price_yearly price_monthly price_discount_yearly payment_interval_months
].freeze
- FIELDS =
[*STRING_FIELDS, *DATE_FIELDS, *INTEGER_FIELDS].freeze
Instance Attribute Summary
Attributes inherited from BaseModel
#persisted
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Findable
#reload
Methods inherited from BaseModel
#==, define_attribute_methods, define_attributes, #initialize, #persist!, #persisted?
#inspect
Constructor Details
This class inherits a constructor from KB::BaseModel
Class Method Details
.find_by_contract_number(contract_number) ⇒ Object
10
11
12
|
# File 'lib/kb/models/pet_contract.rb', line 10
def self.find_by_contract_number(contract_number)
find("contractnumber/#{contract_number}")
end
|
Instance Method Details
#pet ⇒ Object
60
61
62
|
# File 'lib/kb/models/pet_contract.rb', line 60
def pet
@pet ||= Pet.find(pet_key)
end
|
#plan ⇒ Object
52
53
54
|
# File 'lib/kb/models/pet_contract.rb', line 52
def plan
@plan ||= Plan.all.select { |plan| plan.key == plan_key }
end
|
#product ⇒ Object
56
57
58
|
# File 'lib/kb/models/pet_contract.rb', line 56
def product
@product ||= Product.find product_key
end
|
#save! ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/kb/models/pet_contract.rb', line 38
def save!
return unless changed?
run_callbacks :save do
self.attributes = if @persisted
self.class.update key, changes.transform_values(&:last)
else
self.class.create changes.transform_values(&:last)
end
self
end
end
|