Sha256: 703f12f26669dfc6a51dc7d5f44ccd8f017bea591e0159b2358e3e0c415e3202

Contents?: true

Size: 496 Bytes

Versions: 8

Compression:

Stored size: 496 Bytes

Contents

module Materialist
  module Materializer
    module Internals
      class LinkHrefMapping
        def initialize(key:, as:, url_parser: nil)
          @key = key
          @as = as
          @url_parser = url_parser
        end

        def map(resource)
          return unless link = resource.dig(:_links, @key)
          { @as => url_parser.call(link[:href]) }
        end

        private

        def url_parser
          @url_parser || ->url { url }
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
materialist-3.8.3 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.8.2 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.8.1 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.8.0 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.7.0 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.6.0 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.5.0 lib/materialist/materializer/internals/link_href_mapping.rb
materialist-3.4.0 lib/materialist/materializer/internals/link_href_mapping.rb