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 531
def apipie(context = :method, desc_or_options = nil, options = {}, &block)
  if desc_or_options.is_a?(Hash)
    options = options.merge(desc_or_options)
  elsif desc_or_options.is_a?(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 550
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
  Delegatee.instance_reset
end
method_added(method_name) click to toggle source
Calls superclass method
# File lib/apipie_dsl/dsl.rb, line 588
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 << [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 562
def prepended(klass)
  super
  Delegatee.extension_data.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