This commit is contained in:
yuanke 2016-11-09 15:15:06 +08:00
parent a9c019e3a8
commit 4da08b2e07
1 changed files with 0 additions and 39 deletions

View File

@ -174,43 +174,4 @@ module ActionController
exit 1 exit 1
end end
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 end