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.3.21 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.20 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.19 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.18 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.17 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.16 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.15 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.14 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.13 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.12 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.11g lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.10 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.9 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.8 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.7 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.6 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.5 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.4 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.3 lib/tasks/active_record_utils.rb
trusty-festivity-extension-2.3.2 lib/tasks/active_record_utils.rb