Class: Grape::Formatter::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/formatter/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, env) ⇒ Builder

Returns a new instance of Builder.



10
11
12
13
# File 'lib/grape/formatter/builder.rb', line 10

def initialize(object, env)
  @object, @env = object, env
  @endpoint     = env['api.endpoint']
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



4
5
6
# File 'lib/grape/formatter/builder.rb', line 4

def endpoint
  @endpoint
end

#envObject (readonly)

Returns the value of attribute env.



4
5
6
# File 'lib/grape/formatter/builder.rb', line 4

def env
  @env
end

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/grape/formatter/builder.rb', line 4

def object
  @object
end

Class Method Details

.call(object, env) ⇒ Object



6
7
8
# File 'lib/grape/formatter/builder.rb', line 6

def self.call(object, env)
  new(object, env).call
end

Instance Method Details

#callObject



15
16
17
18
19
20
# File 'lib/grape/formatter/builder.rb', line 15

def call
  return Grape::Formatter::Xml.call(object, env) unless template?

  Grape::Builder::Renderer.new(env['api.tilt.root'], template).
    render(endpoint, locals)
end