Sha256: e11608f8f9816eb798f2a0a6bcfc15ca39a8113db4a3eb681c167a6a20fce1d0

Contents?: true

Size: 1.09 KB

Versions: 28

Compression:

Stored size: 1.09 KB

Contents

module RailsWizard
  module Recipes
    @@categories = {}
    @@list = {}
    
    def self.add(recipe)
      RailsWizard::Recipes.const_set ActiveSupport::Inflector.camelize(recipe.key), recipe
      @@list[recipe.key] = recipe
      (@@categories[recipe.category.to_s] ||= []) << recipe.key
      @@categories[recipe.category.to_s].uniq!
      recipe
    end

    def self.[](key)
      @@list[key.to_s]
    end

    def self.list
      @@list.keys.sort
    end

    def self.list_classes
      @@list.values.sort_by{|c| c.key}
    end

    def self.categories
      @@categories.keys.sort
    end

    def self.for(category)
      (@@categories[category.to_s] || []).sort
    end

    def self.remove_from_category(category, recipe)
      (@@categories[category.to_s] ||= []).delete(recipe.key)
    end

    def self.add_from_directory(directory)
      Dir.foreach(directory) do |file|
        path = File.join(directory, file)
        next unless path.match /\.rb$/
        key = File.basename(path, '.rb')
        recipe = Recipe.generate(key, File.open(path))
        add(recipe)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rails_apps_composer-2.2.16 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.15 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.14 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.13 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.12 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.11 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.10 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.9 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.8 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.7 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.6 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.5 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.4 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.3 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.2 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.1 lib/rails_wizard/recipes.rb
rails_apps_composer-2.2.0 lib/rails_wizard/recipes.rb
rails_apps_composer-2.1.10 lib/rails_wizard/recipes.rb
rails_apps_composer-2.1.9 lib/rails_wizard/recipes.rb
rails_apps_composer-2.1.8 lib/rails_wizard/recipes.rb