Sha256: 0e9e95eae7265e7268b8cf9507958e025111827d9f145ace6ac5eb99c87694eb

Contents?: true

Size: 1.27 KB

Versions: 175

Compression:

Stored size: 1.27 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.clear
      self.list.each do |recipe_key|
        send(:remove_const, ActiveSupport::Inflector.camelize(recipe_key))
      end
      @@categories = {}
      @@list = {}
    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

175 entries across 175 versions & 3 rubygems

Version Path
rails_apps_composer-3.1.36 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.35 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.34 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.33 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.31 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.30 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.29 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.28 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.27 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.25 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.24 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.23 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.22 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.21 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.20 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.19 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.18 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.17 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.16 lib/rails_wizard/recipes.rb
rails_apps_composer-3.1.15 lib/rails_wizard/recipes.rb