Class: AmberComponent::PropDefinition
- Inherits:
-
Object
- Object
- AmberComponent::PropDefinition
- Defined in:
- lib/amber_component/prop_definition.rb
Overview
Internal class which represents a property on a component class.
Instance Attribute Summary collapse
- #allow_nil ⇒ Boolean (also: #allow_nil?) readonly
- #default ⇒ Object, ... readonly
- #name ⇒ Symbol readonly
- #required ⇒ Boolean (also: #required?) readonly
- #type ⇒ Class? readonly
Instance Method Summary collapse
-
#default! ⇒ Object
Evaluate the default value if it’s a ‘Proc` and return the result.
- #default? ⇒ Boolean
-
#initialize(name:, type: nil, required: false, default: nil, allow_nil: false) ⇒ PropDefinition
constructor
A new instance of PropDefinition.
- #type? ⇒ Boolean
Constructor Details
#initialize(name:, type: nil, required: false, default: nil, allow_nil: false) ⇒ PropDefinition
Returns a new instance of PropDefinition.
23 24 25 26 27 28 29 |
# File 'lib/amber_component/prop_definition.rb', line 23 def initialize(name:, type: nil, required: false, default: nil, allow_nil: false) @name = name @type = type @required = required @default = default @allow_nil = allow_nil end |
Instance Attribute Details
#allow_nil ⇒ Boolean (readonly) Also known as: allow_nil?
16 17 18 |
# File 'lib/amber_component/prop_definition.rb', line 16 def allow_nil @allow_nil end |
#default ⇒ Object, ... (readonly)
14 15 16 |
# File 'lib/amber_component/prop_definition.rb', line 14 def default @default end |
#name ⇒ Symbol (readonly)
8 9 10 |
# File 'lib/amber_component/prop_definition.rb', line 8 def name @name end |
#required ⇒ Boolean (readonly) Also known as: required?
12 13 14 |
# File 'lib/amber_component/prop_definition.rb', line 12 def required @required end |
#type ⇒ Class? (readonly)
10 11 12 |
# File 'lib/amber_component/prop_definition.rb', line 10 def type @type end |
Instance Method Details
#default! ⇒ Object
Evaluate the default value if it’s a ‘Proc` and return the result.
48 49 50 51 52 |
# File 'lib/amber_component/prop_definition.rb', line 48 def default! return @default.call if @default.is_a?(::Proc) @default end |
#default? ⇒ Boolean
40 41 42 |
# File 'lib/amber_component/prop_definition.rb', line 40 def default? !@default.nil? end |
#type? ⇒ Boolean
35 36 37 |
# File 'lib/amber_component/prop_definition.rb', line 35 def type? !@type.nil? end |