README.md in smart_initializer-0.8.0 vs README.md in smart_initializer-0.9.0

- old
+ new

@@ -30,23 +30,23 @@ ## Table of contents - [Synopsis](#synopsis) - [Initialization flow](#initialization-flow) - [Attribute value definition flow](#attribute-value-definition-flow-during-object-allocation-and-construction) - - [Constructor definition](#constructor-definition) + - [Constructor definition DSL](#constructor-definition-dsl) - [param](#param) - [option](#option) - [params](#params) - [options](#options) - - [param and params signature](#param-and-params-signature) + - [param and params signature](#param-and-params-signautre) - [option and options signature](#option-and-options-signature) - [Initializer integration](#initializer-integration) - [Basic Example](#basic-example) - [Access to the instance attributes](#access-to-the-instance-attributes) - [Configuration](#configuration) - [Type aliasing](#type-aliasing) -- [Type auto-casting](#type-auto-casting) +- [Type casting](#type-casting) - [Initialization extension](#initialization-extension) - [Plugins](#plugins) - [thy-types](#plugin-thy-types) - [Roadmap](#roadmap) - [Build](#build) @@ -55,26 +55,49 @@ ## Synopsis #### Initialization flow -1. Parameter + Option definitioning and initialization; +1. Parameter + Option definitioning and initialization (custom object allocator and constructor); 2. Original **#initialize** invokation; 3. Initialization extensions invokation; -**NOTE!**: original constructor is called after **SmarteCore::Initializer**'s constructor +**NOTE!**: **SmarteCore::Initializer**'s constructor is invoked first in order to guarantee the validity of the SmartCore::Initializer's functionality (such as `attribute overlap chek`, `instant type checking`, `value post-processing by finalize`, etc) #### Attribute value definition flow (during object allocation and construction): 1. `original value` 2. *(if defined)*: `default value` (default value is used when `original value` is not defined) 3. *(if defined)*: `finalize`; ---- +**NOTE**: `:finalize` block are not invoked on omitted `optional: true` attributes +which has no `:default` definition bock and which are not passed to the constructor. Example: +```ruby +# without :default + +class User + include SmartCore::Initializer + option :age, :string, optional: true, finalize: -> (val) { "#{val}_years" } +end + +User.new.age # => nil +``` + +```ruby +# with :default + +class User + include SmartCore::Initializer + option :age, :string, optional: true, default: '0', finalize: -> (val) { "#{val}_years" } +end + +User.new.age # => '0_years' +``` + ### Constructor definition DSL **NOTE**: last `Hash` argument will be treated as `kwarg`s; #### param @@ -88,11 +111,11 @@ - `mutable` (optional) - generate type-validated attr_writer in addition to attr_reader (`false` by default) - (**limitation**) param has no `:default` option; #### option -- `option` - defined kwarg-like attribute: +- `option` - defines kwarg-like attribute: - `cast` (optional) - type-cast received value if value has invalid type; - `privacy` (optional) - reader incapsulation level; - `as` (optional) - attribute alias (be careful with naming aliases that overlap the names of other attributes); - `mutable` (optional) - generate type-validated attr_writer in addition to attr_reader (`false` by default) - `optional` (optional) - mark attribut as optional (you can may not initialize optional attributes, @@ -104,17 +127,17 @@ - non-proc values will be `dup`licate during initialization; - `type_system` (optional) - differently chosen type system for the current attribute; #### params -- `params` - define a series of parameters; +- `params` - defines a series of parameters; - `:mutable` (optional) - (`false` by default); - `:privacy` (optional) - (`:public` by default); #### options -- `options` - define a series of options; +- `options` - defines a series of options; - `:mutable` (optional) - (`false` by default); - `:privacy` (optional) - (`:public` by default); #### `param` and `params` signautre: @@ -497,10 +520,13 @@ --- ## Roadmap -- (**thinking** / **discussing**) Finalize should be invoked on `mutable` attributes after mutation too; +- More semantic attribute declaration errors (more domain-related attribute error objects); + - incorrect `:finalize` argument type: `ArgumentError` => `FinalizeArgumentError`; + - incorrect `:as` argument type: `ArguemntError` => `AsArgumentError`; + - etc; - Support for `RSpec` doubles and instance_doubles inside the type system integration; - Specs restructuring; - Migrate from `TravisCI` to `GitHub Actions`; - Extract `Type Interop` system to `smart_type-system`;