This commit is contained in:
parent
a9c019e3a8
commit
4da08b2e07
|
@ -175,42 +175,3 @@ module ActionController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Grape
|
||||
class Entity
|
||||
def self.expose(*args, &block)
|
||||
options = merge_options(args.last.is_a?(Hash) ? args.pop : {})
|
||||
|
||||
if args.size > 1
|
||||
fail ArgumentError, 'You may not use the :as option on multi-attribute exposures.' if options[:as]
|
||||
fail ArgumentError, 'You may not use block-setting on multi-attribute exposures.' if block_given?
|
||||
end
|
||||
|
||||
fail ArgumentError, 'You may not use block-setting when also using format_with' if block_given? && options[:format_with].respond_to?(:call)
|
||||
|
||||
options[:proc] = block if block_given? && block.parameters.any?
|
||||
|
||||
@nested_attributes ||= []
|
||||
|
||||
args.each do |attribute|
|
||||
unless @nested_attributes.empty?
|
||||
orig_attribute = attribute.to_sym
|
||||
attribute = "#{@nested_attributes.last}__#{attribute}"
|
||||
nested_attribute_names_hash[attribute.to_sym] = orig_attribute
|
||||
options[:nested] = true
|
||||
nested_exposures_hash[@nested_attributes.last.to_sym] ||= {}
|
||||
nested_exposures_hash[@nested_attributes.last.to_sym][attribute.to_sym] = options
|
||||
end
|
||||
|
||||
exposures[attribute.to_sym] = options
|
||||
|
||||
# Nested exposures are given in a block with no parameters.
|
||||
if block_given? && block.parameters.empty?
|
||||
@nested_attributes << attribute
|
||||
block.call
|
||||
@nested_attributes.pop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue