Class: UpdateTime

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/update_time.rb

Overview

COPYRIGHT:

Copyright (c) 2005-2009 North Carolina State University
Developed with funding for the National eXtension Initiative.

LICENSE:

see LICENSE file

Class Method Summary (collapse)

Class Method Details

+ (Object) find_or_create(datasource, datatype)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/update_time.rb', line 18

def find_or_create(datasource,datatype)
  # allow association at the class level
  if(datasource.is_a?(Class))
    datasource_type = datasource.name
    findconditions = {:datasource_type => datasource_type,:datasource_id => 0, :datatype => datatype}
    createoptions = {:datasource_type => datasource_type, :datasource_id => 0, :datatype => datatype}
  else
    datasource_type = datasource.class.name
    findconditions = {:datasource_type => datasource_type,:datasource_id => datasource.id, :datatype => datatype}
    createoptions = {:datasource => datasource, :datatype => datatype}
  end
    
  find_object = self.find(:first, :conditions => findconditions)
  if(find_object.nil?)
    find_object = create(createoptions)
  end
  return find_object
end