Class: Playbook::Props::Base
- Inherits:
-
Object
- Object
- Playbook::Props::Base
- Defined in:
- lib/playbook/props/base.rb
Direct Known Subclasses
Array, Boolean, Date, Enum, HashArray, HashProp, NestedProps, Number, NumberArray, Numeric, Percentage, Proc, String
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#deprecated ⇒ Object
readonly
Returns the value of attribute deprecated.
-
#kit ⇒ Object
readonly
Returns the value of attribute kit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Instance Method Summary collapse
-
#initialize(name:, kit:, default: nil, deprecated: false, required: false) ⇒ Base
constructor
A new instance of Base.
- #validate(_value) ⇒ Object
- #validate!(input_value) ⇒ Object
- #value(value) ⇒ Object
Constructor Details
#initialize(name:, kit:, default: nil, deprecated: false, required: false) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 16 |
# File 'lib/playbook/props/base.rb', line 10 def initialize(name:, kit:, default: nil, deprecated: false, required: false) @default = default @deprecated = deprecated @required = required @name = name @kit = kit end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
8 9 10 |
# File 'lib/playbook/props/base.rb', line 8 def default @default end |
#deprecated ⇒ Object (readonly)
Returns the value of attribute deprecated.
8 9 10 |
# File 'lib/playbook/props/base.rb', line 8 def deprecated @deprecated end |
#kit ⇒ Object (readonly)
Returns the value of attribute kit.
8 9 10 |
# File 'lib/playbook/props/base.rb', line 8 def kit @kit end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/playbook/props/base.rb', line 8 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
8 9 10 |
# File 'lib/playbook/props/base.rb', line 8 def required @required end |
Instance Method Details
#validate(_value) ⇒ Object
31 32 33 |
# File 'lib/playbook/props/base.rb', line 31 def validate(_value) true end |
#validate!(input_value) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/playbook/props/base.rb', line 22 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 |
#value(value) ⇒ Object
18 19 20 |
# File 'lib/playbook/props/base.rb', line 18 def value(value) value.nil? ? @default : value end |