Sha256: 4dbe0f9cea917c224afaf9b25f249be266ed5e89d291e62d7b51a933b0b75da3

Contents?: true

Size: 599 Bytes

Versions: 3

Compression:

Stored size: 599 Bytes

Contents

# frozen_string_literal: true

module Scim
  module Kit
    # Implement methods necessary to generate json from jbuilder templates.
    module Templatable
      def to_json(options = {})
        render(self, options)
      end

      def as_json(_options = nil)
        to_h
      end

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scim-kit-0.2.16 lib/scim/kit/templatable.rb
scim-kit-0.2.15 lib/scim/kit/templatable.rb
scim-kit-0.2.14 lib/scim/kit/templatable.rb