Sha256: b909ae9140aced12eca217e5c9d1f83d2917e0ab4dbfa96be9624725e7dab63a

Contents?: true

Size: 1.32 KB

Versions: 56

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(default: nil, deprecated: false, required: false, name:, kit:)
        @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

56 entries across 56 versions & 1 rubygems

Version Path
playbook_ui-10.6.1.pre.alpha1 lib/playbook/props/base.rb
playbook_ui-10.6.0 lib/playbook/props/base.rb
playbook_ui-10.5.0 lib/playbook/props/base.rb
playbook_ui-10.4.0 lib/playbook/props/base.rb
playbook_ui-10.3.0 lib/playbook/props/base.rb
playbook_ui-10.2.1.alpha.sisensefix lib/playbook/props/base.rb
playbook_ui-10.2.1 lib/playbook/props/base.rb
playbook_ui-10.2.0 lib/playbook/props/base.rb
playbook_ui-10.1.0 lib/playbook/props/base.rb
playbook_ui-10.0.3.pre.alpha.walkthrough2 lib/playbook/props/base.rb
playbook_ui-10.0.3.pre.alpha.walkthrough lib/playbook/props/base.rb
playbook_ui-10.0.1.alpha.railscusticon lib/playbook/props/base.rb
playbook_ui-10.0.2.pre.alpha.pre.iconfix lib/playbook/props/base.rb
playbook_ui-10.0.1.alpha.rtflexfix lib/playbook/props/base.rb
playbook_ui-10.0.0.pre.alphafonts lib/playbook/props/base.rb
playbook_ui-10.0.1 lib/playbook/props/base.rb
playbook_ui-10.0.0 lib/playbook/props/base.rb
playbook_ui-9.19.0.pre.alpha.pre.fonts2 lib/playbook/props/base.rb
playbook_ui-9.19.0 lib/playbook/props/base.rb
playbook_ui-9.19.0.pre.alphafonts lib/playbook/props/base.rb