Module: ArPerfToolkit::Insert::ClassMethods

Defined in:
lib/insert.rb

Instance Method Summary collapse

Instance Method Details

#create_ignore(attributes = nil) ⇒ Object



33
34
35
# File 'lib/insert.rb', line 33

def create_ignore attributes = nil
  create_x!(attributes, :keywords => 'IGNORE')
end

#create_x(attributes = nil, options = {}) ⇒ Object

Creates an object, instantly saves it as a record (if the validation permits it), and returns it. If the save fails under validations, the unsaved object is still returned.



39
40
41
42
43
44
45
46
47
48
# File 'lib/insert.rb', line 39

def create_x(attributes = nil, options={})
  if attributes.is_a?(Array)
    attributes.collect { |attr| create(attr) }
  else
    object = new(attributes)
    scope(:create).each { |att,value| object.send("#{att}=", value) } if scoped?(:create)
    object.save_x options
    object
  end
end

#create_x!(attributes = nil, options = {}) ⇒ Object

Creates an object just like Base.create but calls save! instead of save so an exception is raised if the record is invalid.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/insert.rb', line 52

def create_x!(attributes = nil,options={})
  if attributes.is_a?(Array)
    attributes.collect { |attr| create!(attr) }
  else
    attributes.reverse_merge!(scope(:create)) if scoped?(:create)

    object = new(attributes)
    object.save_x!(options)
    object
  end
end