Sha256: 74f5345ccb464b0a78a3dedae0f5f8e77cb59bf70153de78418b2062de6013e2

Contents?: true

Size: 709 Bytes

Versions: 3

Compression:

Stored size: 709 Bytes

Contents

$:.unshift File.dirname(__FILE__)

require 'rack_interface/route'

class Usher
  module Interface
    class EmailInterface
      
      def initialize(&blk)
        @routes = Usher.new(:delimiters => ['@', '-', '.'], :valid_regex => '[\+a-zA-Z0-9]+', :globs_capture_separators => true)
        instance_eval(&blk) if blk
      end
      
      def for(path, &block)
        @routes.add_route(path).to(block)
      end

      def reset!
        @routes.reset!
      end

      def act(email)
        response = @routes.recognize(email, email)
        if response.path
          response.path.route.destination.call(response.params.inject({}){|h,(k,v)| h[k]=v.to_s; h })
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
joshbuddy-usher-0.4.5 lib/usher/interface/email_interface.rb
joshbuddy-usher-0.4.6 lib/usher/interface/email_interface.rb
joshbuddy-usher-0.4.7 lib/usher/interface/email_interface.rb