File: validations.rb

package info (click to toggle)
ruby-protected-attributes 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 304 kB
  • ctags: 382
  • sloc: ruby: 1,977; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 698 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'active_support/concern'

module ActiveRecord
  module MassAssignmentSecurity
    module Validations
      extend ActiveSupport::Concern

      module ClassMethods
        # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
        # so an exception is raised if the record is invalid.
        def create!(attributes = nil, options = {}, &block)
          if attributes.is_a?(Array)
            attributes.collect { |attr| create!(attr, options, &block) }
          else
            object = new(attributes, options)
            yield(object) if block_given?
            object.save!
            object
          end
        end
      end
    end
  end
end