Sha256: d1801cd03af3bb9646393a1e42e9eab4e78c094bd7925378bc4ce1fe6bb1e2b8
Contents?: true
Size: 1.81 KB
Versions: 4
Compression:
Stored size: 1.81 KB
Contents
# Hacking document 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. ## Design 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. ## Methods The main methods users directly use are listed below. Class methods (DSL): * `attribute` for block style attribute * `attributes` for symbol style attribute * `association` and its aliases such as `one` for association Instance methods: * `serializable_hash` and `to_h` for hash from target object * `serialize` and `to_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. ## Implementation In `Alba::Resource` module there are some things to note. `@object` is an object for serialization. It's either singular object or collection. Attribute object can be either `Symbol`, `Proc`, `Alba::Association` or `Alba::TypedAttribute`. * `Symbol` attributes come from `attributes` method and are sent to `__send__` as method name * `Proc` attributes come from `attribute` method and are `instance_exec`uted * `Alba::Association` attributes come from `association` method and `to_h` method on the object is called * `Alba::TypedAttribute` attributes come when users specify `type` option and `value` 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.
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
alba-2.2.0 | HACKING.md |
alba-2.1.0 | HACKING.md |
alba-2.0.1 | HACKING.md |
alba-2.0.0 | HACKING.md |