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

Version Path
praxis-2.0.pre.33 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.32 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.31 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.30 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.29 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.28 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.27 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.26 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.25 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.24 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.23 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.22 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.21 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.20 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.19 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.18 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.17 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.16 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb
praxis-2.0.pre.15 tasks/thor/templates/generator/example_app/app/v1/concerns/href.rb