Sha256: e5096533a5b8923e4dd21baafc21ad290ae9d95185a95617ee19472a9f998cac
Contents?: true
Size: 1.41 KB
Versions: 5
Compression:
Stored size: 1.41 KB
Contents
# From Extlib module CamelCaseMixin def camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end end # TODO: refactoring: I suggest to use usher/interfaces/rack.rb instead of # usher/interface/rack_interface.rb, it will enable me to simplify this code class Usher module Interface # Get root directory of interfaces of path to specified interface def self.interface_directory File.join(File.dirname(__FILE__), "interface") end # path to file def self.interface_path(name) File.join(self.interface_directory, "#{name}_interface.rb") end # Usher::Interface.for(:rack, &block) 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 # Array of symbols # Usher::Interface.interfaces # => [:email_interface, :merb_interface, :rack_interface, :rails2_2_interface, :rails2_3_interface, :rails3_interface, :text_interface] def self.interfaces Dir["#{self.interface_directory}/*.rb"].map do |interface| File.basename(interface).sub("_interface.rb", "").to_sym end end end end
Version data entries
5 entries across 5 versions & 2 rubygems
Version | Path |
---|---|
joshbuddy-usher-0.5.7 | lib/usher/interface.rb |
usher-0.5.11 | lib/usher/interface.rb |
usher-0.5.10 | lib/usher/interface.rb |
usher-0.5.8 | lib/usher/interface.rb |
usher-0.5.7 | lib/usher/interface.rb |