Sha256: 60cb3f5bee9bab6fecfb0dbe1485ebe0d6632a7dc4a011fe5d8f6c537f983983

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

class Usher
  module Interface

    InterfaceRegistry = {}

    def self.register(name, cls)
      InterfaceRegistry[name] = cls
    end

    register(:email,    File.join(File.dirname(__FILE__), 'interface', 'email'))
    register(:merb,     File.join(File.dirname(__FILE__), 'interface', 'merb'))
    register(:rails20,  File.join(File.dirname(__FILE__), 'interface', 'rails20'))
    register(:rails22,  File.join(File.dirname(__FILE__), 'interface', 'rails22'))
    register(:rails23,  File.join(File.dirname(__FILE__), 'interface', 'rails23'))
    register(:rack,     File.join(File.dirname(__FILE__), 'interface', 'rack'))
    register(:rails3,   File.join(File.dirname(__FILE__), 'interface', 'rails3'))
    register(:text,     File.join(File.dirname(__FILE__), 'interface', 'text'))

    # Usher::Interface.for(:rack, &block)
    def self.for(name, &block)
      name = name.to_sym
      if InterfaceRegistry[name]
        require InterfaceRegistry[name]
        const = Usher::Interface.const_get(File.basename(InterfaceRegistry[name]).to_s.split(/_/).map{|e| e.capitalize}.join)
        const.new(&block)
      else
        raise ArgumentError, "Interface #{name.inspect} doesn't exist. Choose one of: #{InterfaceRegistry.keys.inspect}"
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
usher-0.5.13 lib/usher/interface.rb
usher-0.5.12 lib/usher/interface.rb