Sha256: 72f2983c3d30a1929f6e69f829fb877b5fef3c376cc143bd02f83f58caf147c6

Contents?: true

Size: 926 Bytes

Versions: 3

Compression:

Stored size: 926 Bytes

Contents

module Fakerama
  class Asset

    # Configure files avaiable here
    FILES = {
      'Advert' => ["banner.jpg", "mpu.jpg", "skyscraper.jpg", "small.jpg"],
      'Audio' => ["mp3.mp3", "ogg.ogg", "wav.wav"],
      'Document' => ["doc.doc", "pages.pages", "pdf.pdf", "txt.txt", "xls.xls"],
      'Flash' => ["fla.fla", "swf.swf"],
      'Photo' => ['portrait.jpg', 'landscape.jpg']
    }

    class << self
    private
      def new_file(filename)
        File.new(File.expand_path(File.join(File.dirname(__FILE__),'..','..','assets',folder_name,filename)))
      end

      def folder_name
        name.split('::').last.downcase
      end
    end


    FILES.each_pair do |klass,files|
      const_set(klass, Class.new(Asset) do
        files.each do |file|
          singleton_class.instance_eval do
            define_method(file.split('.').first) { new_file(file) }
          end
        end
      end)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fakerama-0.1.2 lib/fakerama/asset.rb
fakerama-0.1.1 lib/fakerama/asset.rb
fakerama-0.1.0 lib/fakerama/asset.rb