Class: AmberComponent::PropDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/amber_component/prop_definition.rb

Overview

Internal class which represents a property on a component class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type: nil, required: false, default: nil, allow_nil: false) ⇒ 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_nilBoolean (readonly) Also known as: allow_nil?



16
17
18
# File 'lib/amber_component/prop_definition.rb', line 16

def allow_nil
  @allow_nil
end

#defaultObject, ... (readonly)



14
15
16
# File 'lib/amber_component/prop_definition.rb', line 14

def default
  @default
end

#nameSymbol (readonly)



8
9
10
# File 'lib/amber_component/prop_definition.rb', line 8

def name
  @name
end

#requiredBoolean (readonly) Also known as: required?



12
13
14
# File 'lib/amber_component/prop_definition.rb', line 12

def required
  @required
end

#typeClass? (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