lib/spreadsheet_agent/agent.rb
def process!(&agent_code)
      @worksheet.reload
      no_problems = true
      capture_output = nil
      unless @debug
        capture_output = CaptureIO.new
        capture_output.start
      end

      begin
        return true if has_conflicts()
        (runnable, entry) = run_entry()
        return false unless entry
        return true unless runnable
      
        success, update_entry = agent_code.call(entry)
        if success
          complete_entry(update_entry)
        else
          fail_entry(update_entry)
        end
      rescue
        $stderr.puts "#{ $! }"
        no_problems = false
      end
      unless capture_output.nil?
        if no_problems
          capture_output.stop
        else
          mail_error(capture_output.stop)
        end
      end
      return no_problems
    end
def process!(&agent_code)
      @worksheet.reload
      no_problems = true
      capture_output = nil
      unless @debug
        capture_output = CaptureIO.new
        capture_output.start
      end

      begin
        return true if has_conflicts()
        (runnable, entry) = run_entry()
        return false unless entry
        return true unless runnable
      
        success, update_entry = agent_code.call(entry)
        if success
          complete_entry(update_entry)
        else
          fail_entry(update_entry)
        end
      rescue
        $stderr.puts "#{ $! }"
        no_problems = false
      end
      unless capture_output.nil?
        if no_problems
          capture_output.stop
        else
          mail_error(capture_output.stop)
        end
      end
      return no_problems
    end
def process! ( & agent_code ) @worksheet . reload no_problems = true capture_output = nil unless @debug capture_output = CaptureIO . new capture_output . start end begin return true if has_conflicts ( ) ( runnable , entry ) = run_entry ( ) return false unless entry return true unless runnable success , update_entry = agent_code . call ( entry ) if success complete_entry ( update_entry ) else fail_entry ( update_entry ) end rescue $stderr . puts "#{ $! }" no_problems = false end unless capture_output . nil? if no_problems capture_output . stop else mail_error ( capture_output . stop ) end end return no_problems end
create a new SpreadsheetAgent::Agent
 @param attributes [Hash] keys are the attribute names, values are their values
 @option attributes [String] agent_name REQUIRED
 @option attributes [String] page_name REQUIRED
 @option attributes [Hash] keys REQUIRED
 @option attributes [String] config_file (see SpreadsheetAgent::DB)
 @option attributes [Boolean] debug
 @option attributes [Array] prerequisites
 @option attributes [Integer] max_selves
 @option attributes [Hash] conflicts_with
 @option attributes [Array] subsumes
 If the agent does not have any conflicting processes (max_selves or conflicts_with)
 and if the entry field 'ready' has a 1, and any supplied prerequisite fields have a 1,
 gets the GoogleDrive::List[http://rubydoc.info/gems/google_drive/0.3.6/GoogleDrive/List] record, and
 passes it to the supplied Proc. This PROC must return a required boolean field indicating success or failure,
 and an optional hash of key - value fields that will be updated on the GoogleDrive::List record.  Note, the updates
 are made regardless of the value of success.  In fact, the agent can be configured to update
 different fields based on success or failure.   Also, note that any value can be stored in the
 hash.  This allows the agent to communicate any useful information to the google spreadsheet for other
 agents (SpreadsheetAgent::Agent, SpreadsheetAgent::Runner, or human) to use. The Proc must try at all
 costs to avoid terminating. If an error is encountered, it should return false for the success field
 to signal that the process failed.  If no errors are encountered it should return true for the success
 field.

 @example Exit successfully, enters a 1 in the agent_name field
   $agent->process! do |entry|
     true
   end

 @example Same, but also updates the 'notice' field in the record along with the 1 in the agent_name field
   $agent->process! do |entry|
     [true, {:notice => 'There were 30 files processed'}]
   end

 @example Fails, enters f:server_hostname in the agent_name field
   $agent->process! do |entry|
     false

 @example Same, but also updates the 'notice' field in the record along with the failure notice
   $agent->process! do |entry|
     [false, {:notice => 'There were 10 files left to process!' }]
   end

 @example This agent passes different parameters based on success or failure
   $agent->process! do |entry|
     if $success
       true
     else
       [ false, {:notice => 'there were 10 remaining files'}]
     end
   end

 @param agent_code [Proc] Code to process entry
 @yieldparam [GoogleDrive::List] entry
 @yieldreturn [Boolean, Hash] success, (optional) hash of fields to update and values to update on the fields
create a new SpreadsheetAgent :: Agent @param attributes [ Hash ] keys are the attribute names values are their values @option attributes [ String ] agent_name REQUIRED @option attributes [ String ] page_name REQUIRED @option attributes [ Hash ] keys REQUIRED @option attributes [ String ] config_file ( see SpreadsheetAgent :: DB ) @option attributes [ Boolean ] debug @option attributes [ Array ] prerequisites @option attributes [ Integer ] max_selves @option attributes [ Hash ] conflicts_with @option attributes [ Array ] subsumes If the agent does not have any conflicting processes ( max_selves or conflicts_with ) and if the entry field ready has a 1 and any supplied prerequisite fields have a 1 gets the GoogleDrive :: List [ http : // rubydoc . info / gems / google_drive / 0 . 3 . 6 / GoogleDrive / List ] record and passes it to the supplied Proc . This PROC must return a required boolean field indicating success or failure and an optional hash of key - value fields that will be updated on the GoogleDrive :: List record . Note the updates are made regardless of the value of success . In fact the agent can be configured to update different fields based on success or failure . Also note that any value can be stored in the hash . This allows the agent to communicate any useful information to the google spreadsheet for other agents ( SpreadsheetAgent :: Agent SpreadsheetAgent :: Runner or human ) to use . The Proc must try at all costs to avoid terminating . If an error is encountered it should return false for the success field to signal that the process failed . If no errors are encountered it should return true for the success field .