This document is intended to provide detailed information about the internal design and implementation of Alba. You are recommended to read through it if you want to hack Alba.
The design of Alba is simple. Alba::Resource
module is the only interface end users use by include
ing it. Other classes and modules are referenced by Alba::Resource
.
When a class include
s Alba::Resource
module it defines ClassMethods
such as attributes
and InstanceMethods
such as serialize
. Instance methods work with information collected by class methods.
The main methods users directly use are listed below.
Class methods (DSL):
attribute
for block style attributeattributes
for symbol style attributeassociation
and its aliases such asone
for associationnested
for nested attribute
Instance methods:
serializable_hash
andto_h
for hash from target objectserialize
andto_json
for serialized JSON string
Other methods are rather trivial. They'll be added to this list when it turned out it's important enough.
In Alba::Resource
module there are some things to note.
@object
is an object for serialization. It's either a singular object or a collection.
Attribute object can be either Symbol
, Proc
, Alba::Association
or Alba::TypedAttribute
.
Symbol
attributes come fromattributes
method and are sent to__send__
as method nameProc
attributes come fromattribute
method and areinstance_exec
utedAlba::Association
attributes come fromassociation
method andto_h
method on the object is calledAlba::TypedAttribute
attributes come when users specifytype
option andvalue
method on the object is called
When users provide if
option, the attribute object becomes an Array
. It contains two element, attribute itself and condition.