Module: RailsWizard::Recipes

Defined in:
lib/rails_wizard/recipes.rb

Constant Summary collapse

@@categories =
{}
@@list =
{}

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



22
23
24
# File 'lib/rails_wizard/recipes.rb', line 22

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

.add(recipe) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rails_wizard/recipes.rb', line 6

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

.add_from_directory(directory) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/rails_wizard/recipes.rb', line 46

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

.categoriesObject



34
35
36
# File 'lib/rails_wizard/recipes.rb', line 34

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

.clearObject



14
15
16
17
18
19
20
# File 'lib/rails_wizard/recipes.rb', line 14

def self.clear
  self.list.each do |recipe_key|
    send(:remove_const, ActiveSupport::Inflector.camelize(recipe_key))
  end
  @@categories = {}
  @@list = {}
end

.for(category) ⇒ Object



38
39
40
# File 'lib/rails_wizard/recipes.rb', line 38

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

.listObject



26
27
28
# File 'lib/rails_wizard/recipes.rb', line 26

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

.list_classesObject



30
31
32
# File 'lib/rails_wizard/recipes.rb', line 30

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

.remove_from_category(category, recipe) ⇒ Object



42
43
44
# File 'lib/rails_wizard/recipes.rb', line 42

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