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.0.0.pre.alpha9 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha8 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha7 app/pb_kits/playbook/props/base.rb
playbook_ui-6.4.1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha6 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha5 app/pb_kits/playbook/props/base.rb
playbook_ui-6.4.0 app/pb_kits/playbook/props/base.rb
playbook_ui-6.3.1 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha4 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha3 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha2 app/pb_kits/playbook/props/base.rb
playbook_ui-6.3.0 app/pb_kits/playbook/props/base.rb
playbook_ui-6.2.1 app/pb_kits/playbook/props/base.rb
playbook_ui-6.2.0 app/pb_kits/playbook/props/base.rb
playbook_ui-7.0.0.pre.alpha1 app/pb_kits/playbook/props/base.rb
playbook_ui-6.1.0.pre.alpha5 app/pb_kits/playbook/props/base.rb
playbook_ui-6.1.0.pre.alpha4 app/pb_kits/playbook/props/base.rb
playbook_ui-6.1.0.pre.alpha3 app/pb_kits/playbook/props/base.rb
playbook_ui-6.1.0.pre.alpha2 app/pb_kits/playbook/props/base.rb
playbook_ui-6.1.0.pre.alpha1 app/pb_kits/playbook/props/base.rb