Sha256: 293ae248f3aad4141abb148d71544f3d558b63b079b12cf7f31e8e7578e693df

Contents?: true

Size: 738 Bytes

Versions: 152

Compression:

Stored size: 738 Bytes

Contents

# frozen_string_literal: true

module Playbook
  module Props
    class Error < StandardError; end

    class Base
      attr_reader :default, :required

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

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

      def validate!(input_value)
        raise(Playbook::Props::Error, "#{inspect} is a required prop and needs to be provided a value") if required && input_value.nil?

        validate(value(input_value)) ||
          raise(Playbook::Props::Error, "Invalid value (#{input_value.inspect}) for prop (#{inspect})")
      end

      def validate(_value)
        true
      end
    end
  end
end

Version data entries

152 entries across 152 versions & 1 rubygems

Version Path
playbook_ui-7.3.0.pre.alpha2 app/pb_kits/playbook/props/base.rb
playbook_ui-7.1.2 app/pb_kits/playbook/props/base.rb
playbook_ui-7.1.0.pre.alpha2 app/pb_kits/playbook/props/base.rb
playbook_ui-7.1.1.pre.alpha1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.1.1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.1.0.pre.alpha1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.1.0 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.1.pre.alpha15 app/pb_kits/playbook/props/base.rb
playbook_ui-6.8.2.pre.alpha1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha15 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.1.pre.alpha14 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha14 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha13 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha12 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha11 app/pb_kits/playbook/props/base.rb
playbook_ui-6.8.1 app/pb_kits/playbook/props/base.rb
playbook_ui-6.8.0 app/pb_kits/playbook/props/base.rb
playbook_ui-6.7.0.pre.alpha1 app/pb_kits/playbook/props/base.rb