class SeedBed

Attributes

path[RW]

Public Class Methods

available_seeds() click to toggle source
# File lib/seedbed.rb, line 32
def self.available_seeds
  @path = "db/seeds"
  basedir = File.join( File.expand_path(@path), "**" , "*.rb")
  files = Dir.glob( basedir ).collect{|d| d.split( File.expand_path(@path) ).last.split('/')[1..-1].collect{|s| s.split('.rb').first.to_sym} }
  namespaces = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
  files.each do |path|
    sub = namespaces
    path.each{ |dir| sub[dir]; sub = sub[dir] }
  end
  namespaces
end
debug() click to toggle source
# File lib/seedbed.rb, line 28
def self.debug
  @@debug
end
debug=(d) click to toggle source
# File lib/seedbed.rb, line 24
def self.debug=(d)
  @@debug = d
end
message( msg ) click to toggle source
# File lib/seedbed.rb, line 16
def self.message( msg )
  puts ""
  puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
  puts msg
  puts ""
  puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
end
tasks() click to toggle source
# File lib/seedbed.rb, line 44
def self.tasks
  build_tree( SeedBed.available_seeds )
end

Private Class Methods

build_tree(b) click to toggle source
# File lib/seedbed.rb, line 50
def self.build_tree(b)
  fil = ""
  b.keys.each do |t|
    fil << "desc \"plants seeds for #{t}\" \n"
    
    fil << "task :#{t} => :environment do |tsk| \n"
      fil << "puts tsk.scope[2..-1].join('/') \n"
      fil << "SeedBed.plant( tsk.scope[2..-1].join('/') + '/' + '#{t}' )\n"
    fil << "end \n"
    unless b[t].empty?
      fil << "namespace :#{t} do \n"
        fil << build_tree( b[t]  )
        fil << "\n"
      fil << "end \n"
    end
  end
  fil
  # branch.keys.reject{|k| branch[k].empty? }.each do |ns|
  #   namespace ns do
  #     branch[ns].keys.each do |t|
  #       desc "Runs seed for #{t}"
  #       task t do
  #         puts "task #{t}"
  #       end
  #     end
  #   end
  # end
end

Public Instance Methods

plant( file ) { |self| ... } click to toggle source
# File lib/seedbed.rb, line 6
def plant( file )
  @path = "db/seeds"
  # load File.expand_path("#{@path}/../../Rakefile")
  yield self if block_given?
  expanded_path = File.expand_path("#{@path}/#{file.to_s}.rb")
  puts "Growing #{expanded_path}" if SeedBed.debug
  require expanded_path
  
end