def self.expose(*args, &block)
options = merge_options(args.last.is_a?(Hash) ? args.pop : {})
if args.size > 1
raise ArgumentError, 'You may not use the :as option on multi-attribute exposures.' if options[:as]
raise ArgumentError, 'You may not use block-setting on multi-attribute exposures.' if block_given?
end
raise ArgumentError, 'You may not use block-setting when also using format_with' if block_given? && options[:format_with].respond_to?(:call)
if block_given?
if block.parameters.any?
options[:proc] = block
else
options[:nesting] = true
end
end
@documentation = nil
@nesting_stack ||= []
args.each do |attribute|
exposure = Exposure.new(attribute, options)
if @nesting_stack.empty?
root_exposures << exposure
else
@nesting_stack.last.nested_exposures << exposure
end
if exposure.nesting?
@nesting_stack << exposure
block.call
@nesting_stack.pop
end
end
end