README.md in smart_initializer-0.1.0.alpha3 vs README.md in smart_initializer-0.1.0.alpha4
- old
+ new
@@ -18,12 +18,26 @@
require 'smart_core/types'
```
---
+## Table of contents
+
+- [Synopsis](#synopsis)
+- [Type Aliasing](#type-aliasing)
+- [Initialization extension](#initialization-extension)
+
+---
+
## Synopsis
+**Initialization flow**:
+
+1. Parameter + Option definitioning;
+2. Original #initialize invokation;
+3. Initialization extensions invokation;
+
**Constructor definition**:
- `param` - defines name-like attribute:
- `cast` - type-cast received value if value has invalid type;
- `privacy` - reader incapsulation level;
@@ -76,19 +90,63 @@
---
## Type aliasing
+- Usage:
+
```ruby
# define your own type alias
SmartCore::Initializer.type_alias(:hash, SmartCore::Types::Value::Hash)
class User
include SmartCore::Initializer
param :data, :hash # use your new defined type alias
option :metadata, :hash # use your new defined type alias
end
+```
+
+- Predefined aliases:
+ - `:nil` => `SmartCore::Types::Value::Nil`
+ - `:string` => `SmartCore::Types::Value::String`
+ - `:symbol` => `SmartCore::Types::Value::Symbol`
+ - `:text` => `SmartCore::Types::Value::Text`
+ - `:integer` => `SmartCore::Types::Value::Integer`
+ - `:float` => `SmartCore::Types::Value::Float`
+ - `:numeric` => `SmartCore::Types::Value::Numeric`
+ - `:boolean` => `SmartCore::Types::Value::Boolean`
+ - `:array` => `SmartCore::Types::Value::Array`
+ - `:hash` => `SmartCore::Types::Value::Hash`
+ - `:proc` => `SmartCore::Types::Value::Proc`
+ - `:class` => `SmartCore::Types::Value::Class`
+ - `:module` => `SmartCore::Types::Value::Module`
+ - `:any` => `SmartCore::Types::Value::Any`
+
+---
+
+## Initialization extension
+
+- `ext_init(&block)`:
+ - you can define as many extensions as you want;
+ - extensions are invoked in the order they are defined;
+
+```ruby
+class User
+ include SmartCore::Initializer
+
+ option :name, :name
+ option :age, :integer
+
+ ext_init { |instance| instance.define_singleton_method(:extra) { :ext1 } }
+ ext_init { |instance| instance.define_singleton_method(:extra2) { :ext2 } }
+end
+
+user = User.new(name: 'keka', age: 123)
+user.name # => 'keka'
+user.age # => 123
+user.extra # => :ext1
+user.extra2 # => :ext2
```
---
## Contributing