Sha256: 6870e325f66f890799633825f249cfe07c66eb840f2076b4cbf99d3bb40a1f98

Contents?: true

Size: 1.51 KB

Versions: 44

Compression:

Stored size: 1.51 KB

Contents

require 'spf/util'

module SPF
  class MacroString

    def self.default_split_delimiters
      '.'
    end

    def self.default_join_delimiter
      '.'
    end

    def self.uri_unreserved_chars
      'A-Za-z0-9\-._~'
    end

    def initialize(options = {})
      super()
      @text     = options[:text] \
        or raise ArgumentError, "Missing required 'text' option"
      @server   = options[:server]
      @request  = options[:request]
      @expanded = nil
      self.expand
    end

    attr_reader :text, :server, :request

    def context(server, request)
      valid_context(true, server, request)
      @server   = server
      @request  = request
      @expanded = nil
      return
    end

    def expand(context = nil)
      return @expanded if @expanded

      return nil unless @text
      return (@expanded = @text) unless @text =~ /%/
        # Short-circuit expansion if text has no '%' characters.

      expanded = ''
      # TODO
      return (@expanded = @text)
    end

    def to_s
      if valid_context(false)
        return expand
      else
        return @text
      end
    end

    def valid_context(required, server = self.server, request = self.request)
      if not SPF::Server === server
        raise MacroExpansionCtxRequired, 'SPF server object required' if required
        return false
      end
      if not SPF::Request === request
        raise MacroExpansionCtxRequired, 'SPF request object required' if required
        return false
      end
      return true
    end

  end
end

# vim:sw=2 sts=2

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
spf-0.0.23 lib/spf/macro_string.rb
spf-0.0.22 lib/spf/macro_string.rb
spf-0.0.21 lib/spf/macro_string.rb
spf-0.0.20 lib/spf/macro_string.rb
spf-0.0.19 lib/spf/macro_string.rb
spf-0.0.18 lib/spf/macro_string.rb
spf-0.0.17 lib/spf/macro_string.rb
spf-0.0.16 lib/spf/macro_string.rb
spf-0.0.15 lib/spf/macro_string.rb
spf-0.0.14 lib/spf/macro_string.rb
spf-0.0.13 lib/spf/macro_string.rb
spf-0.0.12 lib/spf/macro_string.rb
spf-0.0.11 lib/spf/macro_string.rb
spf-0.0.10 lib/spf/macro_string.rb
spf-0.0.9 lib/spf/macro_string.rb
spf-0.0.8 lib/spf/macro_string.rb
spf-0.0.7 lib/spf/macro_string.rb
spf-0.0.6 lib/spf/macro_string.rb
spf-0.0.5 lib/spf/macro_string.rb
spf-0.0.4 lib/spf/macro_string.rb