mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-25 15:42:57 +00:00
Passes parameters to the function on invoke rather than on class initialization
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
module Schemable
|
||||
class IncludedSchemaGenerator
|
||||
attr_accessor :model_definition, :schema_modifier, :configuration, :relationships, :expand, :relationships_to_exclude_from_expansion
|
||||
attr_accessor :model_definition, :schema_modifier, :relationships
|
||||
|
||||
def initialize(model_definition, relationships_to_exclude_from_expansion: [], expand: false)
|
||||
@expand = expand
|
||||
def initialize(model_definition)
|
||||
@model_definition = model_definition
|
||||
@schema_modifier = SchemaModifier.new
|
||||
@configuration = Schemable.configuration
|
||||
@relationships = @model_definition.relationships
|
||||
@relationships_to_exclude_from_expansion = relationships_to_exclude_from_expansion
|
||||
end
|
||||
|
||||
def generate(expand: false, relationships_to_exclude_from_expansion: [])
|
||||
@@ -56,7 +53,7 @@ module Schemable
|
||||
|
||||
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:)
|
||||
relationships_schema = RelationshipSchemaGenerator.new(model_definition).generate(relationships_to_exclude_from_expansion:, expand:)
|
||||
|
||||
{
|
||||
type: :object,
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
module Schemable
|
||||
class RelationshipSchemaGenerator
|
||||
attr_accessor :model_definition, :schema_modifier, :configuration, :relationships, :expand, :relationships_to_exclude_from_expansion
|
||||
attr_accessor :model_definition, :schema_modifier, :relationships
|
||||
|
||||
def initialize(model_definition, relationships_to_exclude_from_expansion: [], expand: false)
|
||||
@expand = expand
|
||||
def initialize(model_definition)
|
||||
@model_definition = model_definition
|
||||
@schema_modifier = SchemaModifier.new
|
||||
@configuration = Schemable.configuration
|
||||
@relationships = model_definition.relationships
|
||||
@relationships_to_exclude_from_expansion = relationships_to_exclude_from_expansion
|
||||
end
|
||||
|
||||
def generate
|
||||
def generate(relationships_to_exclude_from_expansion: [], expand: false)
|
||||
return {} if @relationships.blank? || @relationships == { belongs_to: {}, has_many: {} }
|
||||
|
||||
schema = {
|
||||
@@ -35,7 +32,7 @@ module Schemable
|
||||
|
||||
result = relation_type == :belongs_to ? generate_schema(definition.model_name) : generate_schema(definition.model_name, collection: true)
|
||||
|
||||
result = non_expanded_data_properties if !expand || @relationships_to_exclude_from_expansion.include?(definition.model_name)
|
||||
result = non_expanded_data_properties if !expand || relationships_to_exclude_from_expansion.include?(definition.model_name)
|
||||
|
||||
schema[:properties].merge!(relation => result)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user