Module: Usher::Interface

Defined in:
lib/usher/interface.rb,
lib/usher/interface/merb_interface.rb,
lib/usher/interface/rack_interface.rb,
lib/usher/interface/text_interface.rb,
lib/usher/interface/email_interface.rb,
lib/usher/interface/rails3_interface.rb,
lib/usher/interface/rails2_2_interface.rb,
lib/usher/interface/rails2_3_interface.rb,
lib/usher/interface/rack_interface/route.rb,
lib/usher/interface/rails2_2_interface/mapper.rb

Defined Under Namespace

Classes: EmailInterface, MerbInterface, RackInterface, Rails22Interface, Rails23Interface, Rails3Interface, TextInterface

Class Method Summary collapse

Class Method Details

.for(name, &block) ⇒ Object

Usher::Interface.for(:rack, &block)



24
25
26
27
28
29
30
31
32
# File 'lib/usher/interface.rb', line 24

def self.for(name, &block)
  if File.exist?(self.interface_path(name))
    require self.interface_path(name)
    snake_cased = "#{name}_interface".extend(CamelCaseMixin)
    Usher::Interface.const_get(snake_cased.camel_case).new(&block)
  else
    raise ArgumentError, "Interface #{name} doesn't exist. Choose one of: #{self.interfaces.inspect}"
  end
end

.interface_directoryObject

Get root directory of interfaces of path to specified interface



14
15
16
# File 'lib/usher/interface.rb', line 14

def self.interface_directory
  File.join(File.dirname(__FILE__), "interface")
end

.interface_path(name) ⇒ Object

path to file



19
20
21
# File 'lib/usher/interface.rb', line 19

def self.interface_path(name)
  File.join(self.interface_directory, "#{name}_interface.rb")
end

.interfacesObject

Array of symbols Usher::Interface.interfaces

> [:email_interface, :merb_interface, :rack_interface, :rails2_2_interface, :rails2_3_interface, :rails3_interface, :text_interface]



37
38
39
40
41
# File 'lib/usher/interface.rb', line 37

def self.interfaces
  Dir["#{self.interface_directory}/*.rb"].map do |interface|
    File.basename(interface).sub("_interface.rb", "").to_sym
  end
end