Call this to make exposures to the entity for this Class. Can be called with symbols for the attributes to expose, a block that yields the full Entity DSL (See Grape::Entity), or both.
@example Symbols only.
class User include Grape::Entity::DSL entity :name, :email end
@example Mixed.
class User include Grape::Entity::DSL entity :name, :email do expose :latest_status, using: Status::Entity, if: :include_status expose :new_attribute, :if => {:version => 'v2'} end end
# File lib/grape_entity/entity.rb, line 87 def entity(*exposures, &block) entity_class.expose *exposures if exposures.any? entity_class.class_eval(&block) if block_given? entity_class end
Returns the automatically-created entity class for this Class.
# File lib/grape_entity/entity.rb, line 58 def entity_class(search_ancestors=true) klass = const_get(:Entity) if const_defined?(:Entity) klass ||= ancestors.detect{|a| a.entity_class(false) if a.respond_to?(:entity_class) } if search_ancestors klass end