Class: Castkit::Attributes::Definition
- Inherits:
-
Object
- Object
- Castkit::Attributes::Definition
- Extended by:
- Options
- Defined in:
- lib/castkit/attributes/definition.rb
Overview
Provides a class-based DSL for defining reusable attribute definitions.
Extend this class in a subclass of ‘Castkit::Attributes::Base` to define shared attribute settings that can be reused across multiple DataObjects.
Constant Summary
Constants included from Options
Options::ACCESS_MODES, Options::DEFAULTS
Class Method Summary collapse
-
.define(type, **options) { ... } ⇒ Array<(Symbol, Hash)>
Defines the attribute’s type and configuration using a DSL block.
-
.definition ⇒ Hash
The internal definition hash, containing the type and options.
-
.options ⇒ Hash
The attribute options defined on this class.
Methods included from Options
access, composite, default, force_type, format, ignore, ignore_blank, ignore_nil, of, prefix, readonly, required, transient, type, unwrapped, validator
Class Method Details
.define(type, **options) { ... } ⇒ Array<(Symbol, Hash)>
Defines the attribute’s type and configuration using a DSL block.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/castkit/attributes/definition.rb', line 50 def define(type, **, &block) @__castkit_attribute_dsl = true definition[:type] = type instance_eval(&block) definition[:options] = definition[:options].merge() definition ensure @__castkit_attribute_dsl = false end |
.definition ⇒ Hash
Returns the internal definition hash, containing the type and options.
26 27 28 29 30 31 |
# File 'lib/castkit/attributes/definition.rb', line 26 def definition @definition ||= { type: nil, options: Castkit::Attributes::Options::DEFAULTS.dup } end |
.options ⇒ Hash
Returns the attribute options defined on this class.
34 35 36 |
# File 'lib/castkit/attributes/definition.rb', line 34 def definition[:options] end |