module SerialAttr::Model

Public Instance Methods

attributes_to_serialize() click to toggle source

Generates the list of attribute names for serialization

@return [Array] list of attribute names to serialize

# File lib/serial_attr/model.rb, line 10
def attributes_to_serialize
  attrs = []

  attrs |= self.attributes.keys.collect(&:to_sym) if respond_to?(:attributes)

  attrs |= self.class.serial_attr_whitelist
  attrs -= self.class.serial_attr_blacklist

  attrs.sort
end
serialized_to_hash() click to toggle source

Serialize attributes listed in attributes_to_serialize to a ruby hash

@return [Hash] serialized attributes

# File lib/serial_attr/model.rb, line 24
def serialized_to_hash
  serialized = HashWithIndifferentAccess.new
  self.attributes_to_serialize.each { |key| serialized[key] = send(key) }

  serialized
end
serialized_to_json() click to toggle source

Serialize attributes listed in attributes_to_serialize to JSON

@return [String] attributes serialized to JSON

# File lib/serial_attr/model.rb, line 34
def serialized_to_json
  self.serialized_to_hash.to_json
end