Module: Scim::Kit::Templatable

Overview

Implement methods necessary to generate json from jbuilder templates.

Instance Method Summary collapse

Instance Method Details

#as_json(_options = nil) ⇒ Object



11
12
13
# File 'lib/scim/kit/templatable.rb', line 11

def as_json(_options = nil)
  to_h
end

#render(model, options) ⇒ Object



19
20
21
# File 'lib/scim/kit/templatable.rb', line 19

def render(model, options)
  Template.new(model).to_json(options)
end

#template_nameObject



23
24
25
# File 'lib/scim/kit/templatable.rb', line 23

def template_name
  "#{self.class.name.split('::').last.underscore}.json.jbuilder"
end

#to_hObject



15
16
17
# File 'lib/scim/kit/templatable.rb', line 15

def to_h
  JSON.parse(to_json, symbolize_names: true).with_indifferent_access
end

#to_json(options = {}) ⇒ Object



7
8
9
# File 'lib/scim/kit/templatable.rb', line 7

def to_json(options = {})
  render(self, options)
end