Module: Venduitz::Grape

Defined in:
lib/venduitz/grape.rb

Class Method Summary collapse

Class Method Details

.call(object, env) ⇒ Object

Call method



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/venduitz/grape.rb', line 6

def self.call(object, env)
  # Route Options
  options = env['api.endpoint'].options.fetch :route_options, {}

  # Must define the Representer in the endpoint
  raise 'Must define the Venduitz in the endpoind' if options[:venduitz].nil?

  # Vendtuiz options
  view_options = options[:venduitz_options].nil? ? {} : options[:venduitz_options]

  # Representer options
  view_options[:exclude] ||= []

  # Define the Cache options
  view_options[:cache] ||= Venduitz::Cache.enabled
  view_options[:cache_options] ||= Venduitz::Cache.config

  # Render it!
  options[:venduitz].to_json object, view_options[:exclude], view_options[:cache], view_options[:cache_options]
end