Sha256: ae4771d29861672778705c577eef8d9dad19c5d01bc23442f428586e32a781c9

Contents?: true

Size: 1.3 KB

Versions: 14

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Praxis
  class ActionDefinition
    class HeadersDSLCompiler < Attributor::DSLCompiler
      # it allows to define expectations on incoming headers. For example:
      # header :X_SpecialCookie                        => implies the header is required
      # header :X_Something, /matching_this/           => implies that if the name header exists, it should match the regexp
      # header :X_A_Header, "Specific String"          => implies that the value matches the string exactly
      # In any of the cases, other supported options might be passed
      # header :X_Something, /matching_this/ ,
      #                     required: true             => to make it required
      #                     description: "lorem ipsum" => to describe it (like any other attribute)

      def header(name, val = nil, **options)
        return key name, val, **options if val.is_a?(Class)

        case val
        when Regexp
          options[:regexp] = val
        when String
          options[:values] = [val]
        when nil
          # Defining the existence without any other options can only mean that it is required (otherwise it is a useless definition)
          options[:required] = true if options.empty?
        end
        key name, String, **options
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
praxis-2.0.pre.32 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.31 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.30 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.29 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.28 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.27 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.26 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.25 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.24 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.23 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.22 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.21 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.20 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-2.0.pre.19 lib/praxis/action_definition/headers_dsl_compiler.rb