class RailsWizard::Recipe

Constants

ATTRIBUTES
DEFAULT_ATTRIBUTES

Public Class Methods

<=>(another) click to toggle source
# File lib/rails_wizard/recipe.rb, line 11
def self.<=>(another)
  return -1 if another.run_after.include?(self.key) || self.run_before.include?(another.key)
  return 1 if another.run_before.include?(self.key) || self.run_after.include?(another.key)
  self.key <=> another.key
end
attributes() click to toggle source

The attributes hash containing any set values for

# File lib/rails_wizard/recipe.rb, line 66
def self.attributes
  @attributes ||= DEFAULT_ATTRIBUTES.dup
end
attributes=(hash) click to toggle source
# File lib/rails_wizard/recipe.rb, line 70
def self.attributes=(hash)
  attributes.merge! hash
end
compile() click to toggle source
# File lib/rails_wizard/recipe.rb, line 83
def self.compile
  "# >#{"[ #{name} ]".center(75,'-')}<\n\n# #{description}\nsay_recipe '#{name}'\n\n#{template}\n"
end
config() click to toggle source
# File lib/rails_wizard/recipe.rb, line 74
def self.config
  return nil unless attributes[:config]
  RailsWizard::Config.new(attributes[:config], attributes[:defaults])
end
from_mongo(key) click to toggle source
# File lib/rails_wizard/recipe.rb, line 97
def self.from_mongo(key)
  return key if (key.respond_to?(:superclass) && key.superclass == RailsWizard::Recipe)
  return RailsWizard::Recipes[key] if RailsWizard::Recipes[key]
  raise(RailsWizard::UnknownRecipeError.new(key))
end
generate(key, template_or_file, attributes = {}) click to toggle source
# File lib/rails_wizard/recipe.rb, line 27
def self.generate(key, template_or_file, attributes = {})
  if template_or_file.respond_to?(:read)
    file = template_or_file.read
    parts = file.split(/^__END__$/)
    raise ArgumentError, "The recipe file must have YAML matter after an __END__" unless parts.size == 2
    template = parts.first.strip
    attributes = YAML.load(parts.last).inject({}) do |h,(k,v)|
      h[k.to_sym] = v
      h
    end.merge!(attributes)
  else
    template = template_or_file
  end

  recipe_class = Class.new(RailsWizard::Recipe)
  recipe_class.attributes = attributes
  recipe_class.template = template
  recipe_class.key = key

  recipe_class
end
get_binding() click to toggle source
# File lib/rails_wizard/recipe.rb, line 103
def self.get_binding
  binding
end
to_mongo(value) click to toggle source
# File lib/rails_wizard/recipe.rb, line 88
def self.to_mongo(value)
  case value
    when Class
      value.key
    when String
      value
  end
end

Public Instance Methods

attributes() click to toggle source
# File lib/rails_wizard/recipe.rb, line 79
def attributes
  self.class.attributes
end
compile() click to toggle source
# File lib/rails_wizard/recipe.rb, line 86
def compile; self.class.compile end