Sha256: 7a60b956249d856eb877ad8928b4f9f370b2e01cb6ed05b810cae33b05c4ee3e

Contents?: true

Size: 1.32 KB

Versions: 589

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Playbook
  module Props
    class Error < StandardError; end

    class Base
      attr_reader :default, :deprecated, :required, :name, :kit

      def initialize(name:, kit:, default: nil, deprecated: false, required: false)
        @default = default
        @deprecated = deprecated
        @required = required
        @name = name
        @kit = kit
      end

      def value(value)
        value.nil? ? @default : value
      end

      def validate!(input_value)
        # warn("#{kit} Kit: The prop '#{name}' is deprecated and will be removed in a future release!") if deprecated && input_value # TODO: add some color for pop

        raise(Playbook::Props::Error, "#{kit} prop '#{name}' of type #{inspect.class} is required and needs a value") if required && input_value.nil?

        validate(value(input_value)) ||
          raise(Playbook::Props::Error, "#{kit} has invalid value of '#{input_value.inspect}' for prop '#{name}' of type #{inspect.class}")
      end

      def validate(_value)
        true
      end

    private

      def warn(message)
        log("Prop Warning: #{message}")
      end

      def log(message)
        logger = ActiveSupport::Logger.new($stdout)
        @logger ||= ActiveSupport::TaggedLogging.new(logger)
        @logger.log(0, message)
      end
    end
  end
end

Version data entries

589 entries across 589 versions & 1 rubygems

Version Path
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4316 lib/playbook/props/base.rb
playbook_ui-14.7.0.pre.rc.7 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4312 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4305 lib/playbook/props/base.rb
playbook_ui-14.7.0.pre.rc.6 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4304 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4303 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4296 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1550lazysizesupgrade4295 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4274 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1607dependencydisplayymlupdate4271 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4262 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4260 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1550lazysizesupgrade4257 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4254 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1538READMEroot4251 lib/playbook/props/base.rb
playbook_ui-14.7.0.pre.rc.5 lib/playbook/props/base.rb
playbook_ui-14.6.2.pre.alpha.PLAY1485selectablecardoverflowoutlinebug4247 lib/playbook/props/base.rb
playbook_ui-14.7.0.pre.rc.4 lib/playbook/props/base.rb
playbook_ui-14.7.0.pre.rc.3 lib/playbook/props/base.rb