Sha256: e1d0765d6f28fea3e627955a7b8359fed04911020947b459b031ff6ef06c98c9

Contents?: true

Size: 1.08 KB

Versions: 82

Compression:

Stored size: 1.08 KB

Contents

require "active_record"

class ActiveRecord::Base
  def self.create_or_update_for_site(options = {}, key = :name)
    options["site"] = Site.find(:first, :conditions => {:name => options["site"]})
    Page.current_site = options["site"]
    create_or_update options, key
  end

  def self.create_or_update_for_sites(options = {}, key = :name)
    options["sites"] = options["sites"].collect { |site_name| Site.find(:first, :conditions => {:name => site_name}) }
    create_or_update options, key
  end

  def self.create_or_update(options = {}, key = :id)
    record_from_db = find(:first, :conditions=>{key => options[key.to_s]})
    return record_from_db if record_from_db
    options.delete "overwrite"
    record = record_from_db || new
    record.id = options["id"] if options["id"]
    record.update_attributes!(options)
    record
  end

  def existing_record?
    (not id.nil?)
  end

  def create_or_update_with_attributes! attributes
    puts attributes
    #return if ConvoySeedUtil.create_only && existing_record?
    return if existing_record?
    update_attributes!(attributes)
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.5.3 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.5.2 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.5.1 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.5.0 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.6 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.5 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.4 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.3 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.2 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.1 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.4.0 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.30 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.29 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.28 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.27 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.26 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.25 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.24 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.23 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.22 lib/tasks/active_record_utils.rb