AlchemyCMS/alchemy_cms

View on GitHub
app/models/alchemy/ingredients/boolean.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Alchemy
  module Ingredients
    # A boolean value
    #
    class Boolean < Alchemy::Ingredient
      def value
        ActiveRecord::Type::Boolean.new.cast(self[:value])
      end

      # The localized value
      #
      # Used by the Element#preview_text method.
      #
      def preview_text(_max_length = nil)
        return if value.nil?

        Alchemy.t(value.to_s, scope: "ingredient_values.boolean")
      end
    end
  end
end