TypecastedAttributes

TypecastedAttributes allows types to be declared for your attributes

Types are declared by passing the :type option to the attribute class method. After a type is declared, attribute readers will convert any assigned attribute value to the declared type. If the assigned value cannot be cast, nil will be returned instead. You can access the original assigned value using the before_type_cast methods.

See {Typecasting} for the currently supported types.

Originally part of ActiveAttr, https://github.com/cgriego/active_attr

Constants

  • DEPRECATED_OBJECT_METHODS

Methods

#==

Performs equality checking on the result of attributes and its type.

def ==(other)
  return false unless other.instance_of? self.class
  attributes == other.attributes
end
#[]=

Write a single attribute to the model’s attribute hash.

def write_attribute(name, value)
  if respond_to? "#{name}="
    send "#{name}=", value
  else
    fail Neo4j::UnknownAttributeError, "unknown attribute: #{name}"
  end
end
#attribute_before_type_cast

Read the raw attribute value

def attribute_before_type_cast(name)
  @attributes ||= {}
  @attributes[name.to_s]
end
#attributes

Returns a Hash of all attributes

def attributes
  attributes_map { |name| send name }
end
#write_attribute

Write a single attribute to the model’s attribute hash.

def write_attribute(name, value)
  if respond_to? "#{name}="
    send "#{name}=", value
  else
    fail Neo4j::UnknownAttributeError, "unknown attribute: #{name}"
  end
end