Skip to content

Commit

Permalink
refactor for better debugging: using schema provider instead of copyi…
Browse files Browse the repository at this point in the history
…ng schema
  • Loading branch information
viatcheslavmogilevsky committed Jun 22, 2024
1 parent 63c6ea9 commit 0ecd44d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/struktura23/base-spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Base
include Enforceable

attr_reader :schema, :label, :wrapped_by, :input_enabled, :output_enabled
attr_writer :schemas
attr_writer :schema_provider

def initialize(schema, label=:main)
@schema = schema
Expand Down Expand Up @@ -267,7 +267,7 @@ def wrap_by(wrapper)
end

def wrap
@wrapped_by = Wrapper.new(core_schema: @schema, id: nil, schemas: @schemas)
@wrapped_by = Wrapper.new(core_schema: @schema, id: nil, schema_provider: @schema_provider)
yield(@wrapped_by)
end

Expand Down Expand Up @@ -363,10 +363,6 @@ def schema_provider
end

def schemas
@schemas || []
end

def schemas_from_provider
schema_provider&.schemas || []
end

Expand Down Expand Up @@ -413,7 +409,7 @@ def method_missing(method_name, *args, &block)
when "optional"
Node::Optional.new(schema, *args[1..-1])
end
node.schemas = schemas
node.schema_provider = schema_provider
has!(node, &block)
node
else
Expand All @@ -440,7 +436,7 @@ def has_wrapper(wrapper_key, options={})
schemas.find {|s| s.group_name == :data && s.name == options[:of_data]}
end

named_wrappers[wrapper_key] = wrapper = Wrapper.new(id: wrapper_key, core_schema: schema, schemas: schemas)
named_wrappers[wrapper_key] = wrapper = Wrapper.new(id: wrapper_key, core_schema: schema, schema_provider: schema_provider)
yield(wrapper, wrapper.core)
wrapper
end
Expand Down Expand Up @@ -498,12 +494,12 @@ def to_opentofu
class Wrapper
include Owner

attr_reader :core, :id, :schemas
attr_reader :core, :id, :schema_provider

def initialize(options)
@core = WrapperCore.new(options[:core_schema])
@id = options[:id]
@schemas = options[:schemas]
@schema_provider = options[:schema_provider]
end
end

Expand Down

0 comments on commit 0ecd44d

Please sign in to comment.