class RecipeGenerator

Public Instance Methods

generate_recipe() click to toggle source
# File lib/generators/recipe_generator.rb, line 13
def generate_recipe
  the_options = {}
  settings.each{|s| data = s.split(':'); the_options[data[0]] = data[1] }

  if recipe_name == 'list'
    list_repos
  else
    apply_recipe recipe_name, the_options
  end
end

Private Instance Methods

apply_recipe(the_recipe, the_options) click to toggle source
# File lib/generators/recipe_generator.rb, line 39
def apply_recipe the_recipe, the_options
  if the_recipe.include?('.')
    RecipeGenerator.source_root(Rails.root)
    apply the_recipe, the_options
  elsif the_recipe.starts_with?('http')
    apply the_recipe, the_options
  else
    apply "https://raw.github.com/AgapeRedRecipes/#{the_recipe}/master/recipe.rb", the_options
  end
end
list_repos() click to toggle source
# File lib/generators/recipe_generator.rb, line 25
def list_repos
  require 'net/http'
  require 'uri'

  def open(url)
    Net::HTTP.get(URI.parse(url))
  end

  page_content = JSON.parse(open('https://api.github.com/users/AgapeRedRecipes/repos'))
  repos = page_content.map{|repo| repo['name']}.select{|repo| repo != 'agape-red-recipes'}
  puts "You can apply the following recipes using `rails g recipe [recipe_name] [options]`"
  repos.each{|r| puts "    #{r.downcase}" }
end
open(url) click to toggle source
# File lib/generators/recipe_generator.rb, line 29
def open(url)
  Net::HTTP.get(URI.parse(url))
end