module ApipieDSL::Extension
Public Instance Methods
apipie(context = :method, desc_or_options = nil, options = {}, &block)
click to toggle source
# File lib/apipie_dsl/dsl.rb, line 533 def apipie(context = :method, desc_or_options = nil, options = {}, &block) case desc_or_options when Hash options = options.merge(desc_or_options) when String options[:desc] = desc_or_options end options[:name] ||= context.to_s block = proc {} unless block_given? delegatee = Delegatee.instance_for(self).with(&block) delegatee.short(options[:desc]) # Don't eval the block, since it will be evaluated after method is defined return if context == :method # Currently method extensions are supported only Delegatee.instance_reset end
apipie_update(context = :method, &block)
click to toggle source
# File lib/apipie_dsl/dsl.rb, line 553 def apipie_update(context = :method, &block) block = proc {} unless block_given? delegatee = Delegatee.instance_for(self).with(&block) delegatee.dsl_data[:update_only] = true return if context == :method # Save instance to reuse when actual scope is set Delegatee.extension_data[:class] = delegatee Delegatee.instance_reset end
method_added(method_name)
click to toggle source
Calls superclass method
# File lib/apipie_dsl/dsl.rb, line 594 def method_added(method_name) 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[:methods] << [method_name, dsl_data] ensure Delegatee.instance_reset end
prepended(klass)
click to toggle source
Calls superclass method
# File lib/apipie_dsl/dsl.rb, line 566 def prepended(klass) super 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) unless method_desc raise StandardError, "Could not find method description for #{class_name}##{method_name}. Was the method defined?" end Delegatee.update_method_desc(method_desc, dsl_data) # Define validators for the new method class_scope = self else ApipieDSL.remove_method_description(class_scope, dsl_data[:dsl_versions], method_name) method_desc = ApipieDSL.define_method_description(class_scope, method_name, dsl_data) end Delegatee.instance_reset Delegatee.define_validators(class_scope, method_desc) end ensure Delegatee.instance_reset end