Sha256: 219839d0fc83e06d819ec073b569149a8232810f46d75a11a7eecbf992b261b1

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

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 )
        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
        #orig_attribute name.upcase , String, options
        key name , String, options
      end

      # Override the attribute to really call "key" in the hash (for temporary backwards compat)      
      def attribute(name, attr_type=nil, **opts, &block)
        warn "[DEPRECATION] `attribute` is deprecated when defining headers.  Please use `key` instead."
        key(name, attr_type, **opts, &block)
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
praxis-0.16.1 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.16.0 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.15.0 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.14.0 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.13.0 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.11.2 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.11.1 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.11 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.11pre lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.10.1 lib/praxis/action_definition/headers_dsl_compiler.rb
praxis-0.10.0 lib/praxis/action_definition/headers_dsl_compiler.rb