Class: Journeybook::ComponentRegistry::Component

Inherits:
Data
  • Object
show all
Defined in:
lib/journeybook/component_registry.rb

Constant Summary collapse

DEFAULT_PROP_TYPE =
:short_text

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#component_classObject (readonly)

Returns the value of attribute component_class

Returns:

  • (Object)

    the current value of component_class



3
4
5
# File 'lib/journeybook/component_registry.rb', line 3

def component_class
  @component_class
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



3
4
5
# File 'lib/journeybook/component_registry.rb', line 3

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/journeybook/component_registry.rb', line 3

def name
  @name
end

Instance Method Details

#normalized_propsObject



31
32
33
34
35
# File 'lib/journeybook/component_registry.rb', line 31

def normalized_props
  .fetch(:props, {}).each_with_object({}) do |(prop_name, config), props|
    props[prop_name.to_sym] = normalize_prop(prop_name, config)
  end
end

#schemaObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/journeybook/component_registry.rb', line 6

def schema
  {
    "name" => name.to_s,
    "description" => .fetch(:description, nil),
    "props" => normalized_props.transform_keys(&:to_s).transform_values do |prop|
      {
        "type" => prop[:type].to_s,
        "label" => prop[:label],
        "description" => prop[:description],
        "required" => prop[:required]
      }.tap do |schema|
        next unless prop[:type] == :collection

        schema["min"] = prop[:min]
        schema["max"] = prop[:max]
        schema["item"] = prop[:item].transform_keys(&:to_s)
      end.tap do |schema|
        next unless prop[:type] == :select

        schema["options"] = prop[:options]
      end
    end
  }
end