Module: Redmine::SafeAttributes::ClassMethods

Defined in:
lib/redmine/safe_attributes.rb

Instance Method Summary collapse

Instance Method Details

#safe_attributes(*args) ⇒ Object

Declares safe attributes An optional Proc can be given for conditional inclusion

Example:

safe_attributes 'title', 'pages'
safe_attributes 'isbn', :if => {|book, user| book.author == user}

28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/redmine/safe_attributes.rb', line 28

def safe_attributes(*args)
  @safe_attributes ||= []
  if args.empty?
    if superclass < Redmine::SafeAttributes
      superclass.safe_attributes + @safe_attributes
    else
      @safe_attributes
    end
  else
    options = args.last.is_a?(Hash) ? args.pop : {}
    @safe_attributes << [args, options]
    safe_attributes
  end
end