Sha256: bfeb44d04f81cfa1bce699774c84e9d9450bb0c056b62c4a13809ebf87bffa7d
Contents?: true
Size: 1.84 KB
Versions: 17
Compression:
Stored size: 1.84 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 * `nested` for nested attribute 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 a singular object or a 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
17 entries across 17 versions & 1 rubygems