Skip to content

pier-digital/rubyconf2022

Repository files navigation

Create policy

rails g model Policy start_date:date end_date:date contractable:references\{polymorphic\}
has_many :policies, as: :contractable

Create Claims

rails g model Claim occurrence_date:date type:string
class Smartphone::DamageClaim < Claim
end
class Auto::DamageClaim < Claim
end

Refactor policy and claim

To be refactored:

class Policy < ApplicationRecord
  RATE_IOF = 1.0738
  RATE_BROKERAGE = 0.0001
  validates :premium_value_cents, numericality: {greater_than: 0}
  has_many :premium_movements, dependent: :destroy
  has_many :events, as: :publisher

  aasm do
    before_all_events :memoize_current_attributes
    after_all_events :publish_transition_events
  end

  def publish_created_event
    publish_event("created", data: attributes)
  end
  # ...
end
class Claim < ApplicationRecord
  has_many :claim_movements, dependent: :destroy
  validates :user_id, presence: true
  has_many :events, as: :publisher

  aasm do
    before_all_events :memoize_current_attributes
    after_all_events :publish_transition_events
  end

  def publish_created_event
    publish_event("created", data: attributes)
  end
  # ...
end

New Concern

module EventPublishable
  extend ActiveSupport::Concern
  included do
    has_many :events, as: :publisher
    aasm do
      before_all_events :memoize_current_attributes
      after_all_events :publish_transition_event
    end
  end

  def publish_created_event
    publish_event("created", data: attributes)
  end
  # ...
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages