lib/apipie_dsl/dsl.rb in apipie-dsl-2.2.7 vs lib/apipie_dsl/dsl.rb in apipie-dsl-2.2.8
- old
+ new
@@ -345,11 +345,11 @@
include ApipieDSL::Base
include ApipieDSL::Common
include ApipieDSL::Klass
include ApipieDSL::Method
- attr_reader :class_scope
+ attr_accessor :class_scope
def initialize(class_scope)
@class_scope = class_scope
end
@@ -383,11 +383,11 @@
def self.instance
@instance_for
end
def self.extension_data
- @extension_data ||= []
+ @extension_data ||= { methods: [] }
end
# rubocop:disable Metrics/AbcSize
def self.define_validators(class_scope, method_desc)
return if method_desc.nil? || ![true, :implicitly, :explicitly].include?(ApipieDSL.configuration.validate)
@@ -551,20 +551,23 @@
def apipie_update(context = :method, &block)
block = proc {} unless block_given?
delegatee = Delegatee.instance_for(self).with(&block)
delegatee.dsl_data[:update_only] = true
- # Don't eval the block, since it will be evaluated after method is defined
+
return if context == :method
- # Currently method extensions are supported only
+ # Save instance to reuse when actual scope is set
+ Delegatee.extension_data[:class] = delegatee
Delegatee.instance_reset
end
def prepended(klass)
super
- Delegatee.extension_data.each do |method_name, dsl_data|
+ Delegatee.extension_data[:class]&.class_scope = klass
+ Delegatee.extension_data[:class]&.eval_dsl_for(:class)
+ Delegatee.extension_data[:methods].each do |method_name, dsl_data|
class_scope = klass
if dsl_data[:update_only]
class_name = ApipieDSL.get_class_name(class_scope)
# Update the old method description
method_desc = ApipieDSL.get_method_description(class_name, method_name)
@@ -590,10 +593,10 @@
super
# Methods autoload is not supported for extension modules
return if Delegatee.instance.nil?
dsl_data = Delegatee.instance.eval_dsl_for(:method)
- Delegatee.extension_data << [method_name, dsl_data]
+ Delegatee.extension_data[:methods] << [method_name, dsl_data]
ensure
Delegatee.instance_reset
end
end
end