Sha256: 49f9a51336b9410da9862a7c6ab310b8609d59e3ec46e40b43f37c26b48122f6

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Maquina
  ##
  # A class representing the Plan model in the Maquina module.
  #
  # == Attributes
  #
  # - +price+:: The price of the Plan, represented as a monetary value with currency.
  # - +name+:: The name of the Plan.
  #
  # == Validations
  #
  # - +price+:: Must be greater than or equal to 0 if the Plan is marked as free.
  # - +price+:: Must be greater than 0 if the Plan is not marked as free.
  # - +name+:: Must be present and unique.
  #
  # == Scopes
  #
  # - +search_full+:: Provides a search scope for Plan model, allowing searching by name with options for prefix matching and matching any word.
  #
  # == Usage
  #
  # The Plan model represents a pricing plan in the Maquina module. To use the Plan model, create instances with valid
  # attributes and use the provided methods and scopes for querying and manipulating plan data.

  class Plan < ApplicationRecord
    include Searchable

    monetize :price_cents

    validates :price, numericality: {greater_than_or_equal_to: 0}, if: ->(plan) { plan.free? }
    validates :price, numericality: {greater_than: 0}, if: ->(plan) { !plan.free? }
    validates :name, presence: true, uniqueness: true

    search_scope(fields: [:name])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maquina-0.1.0 app/models/maquina/plan.rb