Sha256: 7a14b20d28d6d6363e8a237c19a4ce30a2d3f240de4243d0a9026ad2a3658135

Contents?: true

Size: 700 Bytes

Versions: 2

Compression:

Stored size: 700 Bytes

Contents

# frozen_string_literal: true

require "securerandom"

module SiteMaps
  Process = Concurrent::ImmutableStruct.new(:name, :location_template, :kwargs_template, :block) do
    def id
      @id ||= SecureRandom.hex(4)
    end

    def location(**kwargs)
      return unless location_template

      location_template % keyword_arguments(kwargs)
    end

    def call(builder, **kwargs)
      return unless block

      block.call(builder, **keyword_arguments(kwargs))
    end

    def static?
      !dynamic?
    end

    def dynamic?
      kwargs_template.is_a?(Hash) && kwargs_template.any?
    end

    def keyword_arguments(given)
      (kwargs_template || {}).merge(given || {})
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
site_maps-0.0.1.beta3 lib/site_maps/process.rb
site_maps-0.0.1.beta2 lib/site_maps/process.rb