Module: Grape::Entity::DSL

Defined in:
lib/grape_entity/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


52
53
54
55
56
# File 'lib/grape_entity/entity.rb', line 52

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

#entity(options = {}) ⇒ Object

Instantiates an entity version of this object.


98
99
100
# File 'lib/grape_entity/entity.rb', line 98

def entity(options = {})
  self.class.entity_class.new(self, options)
end