Class: Lutaml::Model::Schema::BaseSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/schema/base_schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, schema:, id: nil, title: nil, description: nil) ⇒ BaseSchema

Returns a new instance of BaseSchema.



24
25
26
27
28
29
30
# File 'lib/lutaml/model/schema/base_schema.rb', line 24

def initialize(klass, schema:, id: nil, title: nil, description: nil)
  @schema = schema
  @klass = klass
  @id = id
  @title = title
  @description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



22
23
24
# File 'lib/lutaml/model/schema/base_schema.rb', line 22

def description
  @description
end

#idObject

Returns the value of attribute id.



22
23
24
# File 'lib/lutaml/model/schema/base_schema.rb', line 22

def id
  @id
end

#klassObject (readonly)

Returns the value of attribute klass.



21
22
23
# File 'lib/lutaml/model/schema/base_schema.rb', line 21

def klass
  @klass
end

#schemaObject (readonly)

Returns the value of attribute schema.



21
22
23
# File 'lib/lutaml/model/schema/base_schema.rb', line 21

def schema
  @schema
end

#titleObject

Returns the value of attribute title.



22
23
24
# File 'lib/lutaml/model/schema/base_schema.rb', line 22

def title
  @title
end

Class Method Details

.generate(klass, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lutaml/model/schema/base_schema.rb', line 8

def generate(klass, options = {})
  schema = new(
    klass,
    schema: options[:schema],
    id: options[:id],
    title: options[:title],
    description: options[:description],
  ).generate_schema_hash

  format_schema(schema, options)
end

Instance Method Details

#generate_schema_hashObject



32
33
34
35
36
37
38
39
40
# File 'lib/lutaml/model/schema/base_schema.rb', line 32

def generate_schema_hash
  {
    "$schema" => schema,
    "$id" => id,
    "description" => description,
    "$ref" => "#/$defs/#{klass.name.gsub('::', '_')}",
    "$defs" => generate_definitions(klass),
  }.compact
end