Class: Blueprinter::Extensions Private

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprinter/extensions.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Stores and runs Blueprinter extensions. An extension is any object that implements one or more of the extension methods:

The Render Extension intercepts an object before rendering begins. The return value from this method is what is ultimately rendered.

def pre_render(object, blueprint, view, options)
  # returns original, modified, or new object
end

Instance Method Summary collapse

Constructor Details

#initialize(extensions = []) ⇒ Extensions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Extensions.



16
17
18
# File 'lib/blueprinter/extensions.rb', line 16

def initialize(extensions = [])
  @extensions = extensions
end

Instance Method Details

#<<(ext) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Appends an extension



25
26
27
28
# File 'lib/blueprinter/extensions.rb', line 25

def <<(ext)
  @extensions << ext
  self
end

#pre_render(object, blueprint, view, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the object through all Render Extensions and returns the final result



31
32
33
34
35
# File 'lib/blueprinter/extensions.rb', line 31

def pre_render(object, blueprint, view, options = {})
  @extensions.reduce(object) do |acc, ext|
    ext.pre_render(acc, blueprint, view, options)
  end
end

#to_aObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/blueprinter/extensions.rb', line 20

def to_a
  @extensions.dup
end