Advertisement
Guest User

Untitled

a guest
Nov 13th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.17 KB | None | 0 0
  1.     def self.record *args
  2.       options = args.extract_options!
  3.       options.reverse_merge!(:export_time => Time.now,
  4.                              :state => "starting")
  5.       begin
  6.         metadata = ExportMetadata.new
  7.         metadata.set_attributes options
  8.  
  9.         yield metadata
  10.         metadata.store!
  11.       end
  12.     end
  13.  
  14.       ExportMetadata.record(:table => @export_obj.table_name,
  15.                             :database => @export_obj.source_schema,
  16.                             :filepath => filepath) do |metadata|
  17.  
  18.         if @export_obj.state == "new"
  19.           initial_export metadata
  20.     end
  21.       end  
  22.  
  23.     def initial_export metadata
  24.       @export_obj.ssh_to_source do |ssh|
  25.         metadata.ssh = ssh
  26.     metadata.store!
  27.       end
  28.     end
  29.  
  30. -- SSH is set to nil initially in ExportMetadata class
  31. @ssh = nil
  32.  
  33. -- Store method defined in ExportMetadata class
  34.     def store!
  35.       cmd = "cat #{self.to_json} > #{@filepath}.json"
  36.       @ssh.exec!(cmd)
  37.     end
  38.  
  39.  
  40. Calling initial_export throws an exception because @ssh is nil. But it should not be nil, I set in the block:
  41.  
  42. initial_export(metadata)
  43. NoMethodError: undefined method `exec!' for nil:NilClass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement