Module: SerialAttr::Model::ClassMethods

Defined in:
lib/serial_attr/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serial_attr_blacklistObject



45
46
47
# File 'lib/serial_attr/model.rb', line 45

def serial_attr_blacklist
  @serial_attr_blacklist ||= []
end

#serial_attr_whitelistObject



40
41
42
# File 'lib/serial_attr/model.rb', line 40

def serial_attr_whitelist
  @serial_attr_whitelist ||= []
end

Instance Method Details

#serial_attr(*args) ⇒ Object

Adds list of attributes to the serialization whitelist

Note: Blacklist takes precedence over whitelist

Examples:

add a list of attributes

class Person
  include SerialAttr::Model

  serial_attr :name, :address, :phone_number
end

Parameters:

  • args (Symbol, Array)

    list of attributes to add



61
62
63
# File 'lib/serial_attr/model.rb', line 61

def serial_attr(*args)
  self.serial_attr_whitelist |= args
end

#skip_serial_attr(*args) ⇒ Object

Add list of attributes to the serialization blacklist and skip on serialization

Note: Blacklist takes precedence over whitelist

Examples:

skip a list of attributes

class Person
  include ActiveAttr::Model
  include SerialAttr::Model

  attribute :name
  attribute :address
  attribute :phone_number

  skip_serial_attr :phone_number
end

Parameters:

  • args (Symbol, Array)

    list of attributes to skip in serialization



82
83
84
# File 'lib/serial_attr/model.rb', line 82

def skip_serial_attr(*args)
  self.serial_attr_blacklist |= args
end