Class: KB::Plan

Inherits:
BaseModel show all
Includes:
Listable
Defined in:
lib/kb/models/plan.rb

Constant Summary collapse

STRING_FIELDS =
%i[key description plan_name type].freeze
HASH_FIELDS =
%i[benefits price].freeze
FIELDS =
[*STRING_FIELDS, *HASH_FIELDS, :plan_life_in_months, :buyable].freeze

Instance Attribute Summary

Attributes inherited from BaseModel

#persisted

Instance Method Summary collapse

Methods inherited from BaseModel

#==, define_attribute_methods, define_attributes, #initialize, #persist!, #persisted?

Methods included from Inspectionable

#inspect

Constructor Details

This class inherits a constructor from KB::BaseModel

Instance Method Details

#save!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kb/models/plan.rb', line 25

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