Module: Grape::Entity::DSL

Defined in:
lib/grape/entity.rb

Overview

The Entity DSL allows you to mix entity functionality into your existing classes.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



49
50
51
52
53
# File 'lib/grape/entity.rb', line 49

def self.included(base)
  base.extend ClassMethods
  ancestor_entity_class = base.ancestors.detect{|a| a.entity_class if a.respond_to?(:entity_class)}
  base.const_set(:Entity, Class.new(ancestor_entity_class || Grape::Entity)) unless const_defined?(:Entity)
end

Instance Method Details

#entityObject

Instantiates an entity version of this object.



95
96
97
# File 'lib/grape/entity.rb', line 95

def entity
  self.class.entity_class.new(self)
end