cirandas.net

ref: master

lib/sample_data.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module SampleData
  # tourn on autoflush
  STDOUT.sync = true

  environment_id = ARGV.first
  $environment = unless environment_id.blank?
    Environment.find(environment_id)
  else
    Environment.default || Environment.create!(:name => 'Noosfero', :is_default => true)
  end

  def save(obj, &block)
    begin
     if obj.save
       print '.'
       instance_eval &block if block
       return obj
     else
       print 'F'
     end
    rescue
      print 'E'
    end
    return nil
  end

  def done
    puts ' done!'
  end
end