Class: GenerativeUI::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/generative_ui/attributes.rb

Defined Under Namespace

Modules: LocalSchemaBuilders, StructuralDsl Classes: Schema

Constant Summary collapse

METADATA_KEY =
:_generative_ui_structural_ref

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_class) ⇒ Attributes

Returns a new instance of Attributes.



91
92
93
# File 'lib/generative_ui/attributes.rb', line 91

def initialize(schema_class)
  @schema_class = schema_class
end

Instance Attribute Details

#schema_classObject (readonly)

Returns the value of attribute schema_class.



89
90
91
# File 'lib/generative_ui/attributes.rb', line 89

def schema_class
  @schema_class
end

Class Method Details

.build(&block) ⇒ Object



77
78
79
80
# File 'lib/generative_ui/attributes.rb', line 77

def build(&block)
  schema_class = Schema.create(&block)
  new(schema_class)
end

.normalize_only(value) ⇒ Object



82
83
84
85
86
# File 'lib/generative_ui/attributes.rb', line 82

def normalize_only(value)
  return nil if value.nil?

  Array(value).map(&:to_s)
end

Instance Method Details

#json_schemaObject



95
96
97
# File 'lib/generative_ui/attributes.rb', line 95

def json_schema
  @json_schema ||= camelize_schema(schema_class.new.to_json_schema.fetch(:schema))
end

#structural_refsObject



99
100
101
# File 'lib/generative_ui/attributes.rb', line 99

def structural_refs
  @structural_refs ||= extract_structural_refs(json_schema)
end