Sha256: 1369dfae7108df0e93f391ef30e204b0c22c8ceee1b18754dd6c3e3391736189
Contents?: true
Size: 921 Bytes
Versions: 19
Compression:
Stored size: 921 Bytes
Contents
# frozen_string_literal: true module V1 module Resources module Concerns module Href extend ActiveSupport::Concern # Base module where the href concern will grab constants from included do def self.base_module ::V1 end end module ClassMethods def endpoint_path_template # memoize a templated path for an endpoint, like # /im/contacts/%{id} return @endpoint_path_template if @endpoint_path_template path = self.base_module.const_get(:Endpoints).const_get(model.name.split(':').last.pluralize).canonical_path.route.path @endpoint_path_template = path.names.inject(path.to_s) { |p, name| p.sub(':' + name, "%{#{name}}") } end end def href format(self.class.endpoint_path_template, id: id) end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems