Class: Grape::Rabl::Formatter
- Inherits:
-
Object
- Object
- Grape::Rabl::Formatter
- Defined in:
- lib/grape-rabl/formatter.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, env) ⇒ Formatter
constructor
A new instance of Formatter.
- #render ⇒ Object
Constructor Details
#initialize(object, env) ⇒ Formatter
Returns a new instance of Formatter.
14 15 16 17 18 |
# File 'lib/grape-rabl/formatter.rb', line 14 def initialize(object, env) @env = env @endpoint = env['api.endpoint'] @object = object end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
12 13 14 |
# File 'lib/grape-rabl/formatter.rb', line 12 def endpoint @endpoint end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
12 13 14 |
# File 'lib/grape-rabl/formatter.rb', line 12 def env @env end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
12 13 14 |
# File 'lib/grape-rabl/formatter.rb', line 12 def object @object end |
Class Method Details
.tilt_cache ⇒ Object
7 8 9 |
# File 'lib/grape-rabl/formatter.rb', line 7 def tilt_cache @tilt_cache ||= ::Tilt::Cache.new end |
Instance Method Details
#render ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/grape-rabl/formatter.rb', line 20 def render if rablable? rabl do |template| engine = tilt_template(template) output = engine.render endpoint, locals if layout_template layout_template.render(endpoint) { output } else output end end else fallback_formatter.call object, env end end |