Method: Bluepine::Attributes::ObjectAttribute#group

Defined in:
lib/bluepine/attributes/object_attribute.rb

#group(options, &block) ⇒ Object

Apply default options to all attributes

group if: :deleted? { … } group unless: :deleted? { … } group if: ->{ @user.deleted? } { … }



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bluepine/attributes/object_attribute.rb', line 27

def group(options, &block)
  return unless block_given?

  # Use stacks to allow nested conditions
  self.class.stacks << Attribute.options
  Attribute.options = options

  instance_exec(&block)

  # restore options
  Attribute.options = self.class.stacks.pop
end