Class: GenerativeUI::ComponentDefinition
- Inherits:
-
Object
- Object
- GenerativeUI::ComponentDefinition
- Defined in:
- lib/generative_ui/component_definition.rb
Instance Attribute Summary collapse
-
#attributes_definition ⇒ Object
readonly
Returns the value of attribute attributes_definition.
-
#description_text ⇒ Object
readonly
Returns the value of attribute description_text.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes(&block) ⇒ Object
- #attributes_json_schema ⇒ Object
- #component ⇒ Object
- #desc(value) ⇒ Object (also: #description)
-
#initialize(name) ⇒ ComponentDefinition
constructor
A new instance of ComponentDefinition.
- #present_with(adapter, target) ⇒ Object
- #render_target_for(adapter) ⇒ Object
- #structural_refs ⇒ Object
Constructor Details
#initialize(name) ⇒ ComponentDefinition
Returns a new instance of ComponentDefinition.
15 16 17 18 19 20 |
# File 'lib/generative_ui/component_definition.rb', line 15 def initialize(name) @name = name.to_s @description_text = nil @attributes_definition = nil @render_targets = {} end |
Instance Attribute Details
#attributes_definition ⇒ Object (readonly)
Returns the value of attribute attributes_definition.
7 8 9 |
# File 'lib/generative_ui/component_definition.rb', line 7 def attributes_definition @attributes_definition end |
#description_text ⇒ Object (readonly)
Returns the value of attribute description_text.
7 8 9 |
# File 'lib/generative_ui/component_definition.rb', line 7 def description_text @description_text end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/generative_ui/component_definition.rb', line 7 def name @name end |
Class Method Details
.build(name, &block) ⇒ Object
9 10 11 12 13 |
# File 'lib/generative_ui/component_definition.rb', line 9 def self.build(name, &block) definition = new(name) definition.instance_eval(&block) if block definition end |
Instance Method Details
#attributes(&block) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/generative_ui/component_definition.rb', line 31 def attributes(&block) return @attributes_definition unless block raise ArgumentError, "attributes already defined for #{@name}" if @attributes_definition @attributes_definition = Attributes.build(&block) end |
#attributes_json_schema ⇒ Object
55 56 57 58 59 |
# File 'lib/generative_ui/component_definition.rb', line 55 def attributes_json_schema return empty_attributes_schema if @attributes_definition.nil? @attributes_definition.json_schema end |
#component ⇒ Object
22 23 24 |
# File 'lib/generative_ui/component_definition.rb', line 22 def component @name end |
#desc(value) ⇒ Object Also known as: description
26 27 28 |
# File 'lib/generative_ui/component_definition.rb', line 26 def desc(value) @description_text = value.to_s end |
#present_with(adapter, target) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/generative_ui/component_definition.rb', line 38 def present_with(adapter, target) adapter = adapter.to_sym if @render_targets.key?(adapter) raise ArgumentError, "#{@name}: adapter :#{adapter} already declared" end @render_targets[adapter] = target end |
#render_target_for(adapter) ⇒ Object
47 48 49 |
# File 'lib/generative_ui/component_definition.rb', line 47 def render_target_for(adapter) @render_targets[adapter.to_sym] end |
#structural_refs ⇒ Object
51 52 53 |
# File 'lib/generative_ui/component_definition.rb', line 51 def structural_refs @attributes_definition&.structural_refs || [] end |