mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-22 22:26:41 +00:00
Renames method
This commit is contained in:
parent
e2ba1a7b8c
commit
861a740f61
@ -25,7 +25,7 @@ module Schemable
|
|||||||
|
|
||||||
klasses.each do |klass|
|
klasses.each do |klass|
|
||||||
model_definition = klass.new
|
model_definition = klass.new
|
||||||
schema = AttributeSchemaGenerator.new(model_definition).generate_attributes_schema
|
schema = AttributeSchemaGenerator.new(model_definition).generate
|
||||||
generated_schemas << schema
|
generated_schemas << schema
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ module Schemable
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Generate the JSON schema for attributes
|
# Generate the JSON schema for attributes
|
||||||
def generate_attributes_schema
|
def generate
|
||||||
schema = {
|
schema = {
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: @model_definition.attributes.index_with do |attr|
|
properties: @model_definition.attributes.index_with do |attr|
|
||||||
|
|||||||
@ -11,21 +11,6 @@ module Schemable
|
|||||||
@relationships_to_exclude_from_expansion = relationships_to_exclude_from_expansion
|
@relationships_to_exclude_from_expansion = relationships_to_exclude_from_expansion
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_schema_for_included(model_definition, expand: false, relationships_to_exclude_from_expansion: [])
|
|
||||||
attributes_schema = AttributeSchemaGenerator.new(model_definition).generate_attributes_schema
|
|
||||||
relationships_schema = RelationshipSchemaGenerator.new(model_definition, relationships_to_exclude_from_expansion:, expand:)
|
|
||||||
|
|
||||||
{
|
|
||||||
type: :object,
|
|
||||||
properties: {
|
|
||||||
type: { type: :string, default: model_definition.model_name },
|
|
||||||
id: { type: :string },
|
|
||||||
attributes: attributes_schema,
|
|
||||||
relationships: relationships_schema ? {} : relationships_schema
|
|
||||||
}
|
|
||||||
}.compact_blank
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate(expand: false, relationships_to_exclude_from_expansion: [])
|
def generate(expand: false, relationships_to_exclude_from_expansion: [])
|
||||||
return {} if @relationships.blank?
|
return {} if @relationships.blank?
|
||||||
return {} if @relationships == { belongs_to: {}, has_many: {} }
|
return {} if @relationships == { belongs_to: {}, has_many: {} }
|
||||||
@ -68,5 +53,20 @@ module Schemable
|
|||||||
|
|
||||||
schema
|
schema
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_schema_for_included(model_definition, expand: false, relationships_to_exclude_from_expansion: [])
|
||||||
|
attributes_schema = AttributeSchemaGenerator.new(model_definition).generate
|
||||||
|
relationships_schema = RelationshipSchemaGenerator.new(model_definition, relationships_to_exclude_from_expansion:, expand:)
|
||||||
|
|
||||||
|
{
|
||||||
|
type: :object,
|
||||||
|
properties: {
|
||||||
|
type: { type: :string, default: model_definition.model_name },
|
||||||
|
id: { type: :string },
|
||||||
|
attributes: attributes_schema,
|
||||||
|
relationships: relationships_schema ? {} : relationships_schema
|
||||||
|
}
|
||||||
|
}.compact_blank
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,7 +7,7 @@ module Schemable
|
|||||||
attr_accessor schema_modifier: SchemaModifier
|
attr_accessor schema_modifier: SchemaModifier
|
||||||
|
|
||||||
def initialize: (Definition) -> void
|
def initialize: (Definition) -> void
|
||||||
def generate_attributes_schema: -> (Hash[Symbol, any] | Array[any])
|
def generate: -> (Hash[Symbol, any] | Array[any])
|
||||||
def generate_attribute_schema: (Symbol) -> Hash[Symbol, any]
|
def generate_attribute_schema: (Symbol) -> Hash[Symbol, any]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user