Class: Morpher::Record
- Inherits:
-
Module
- Object
- Module
- Morpher::Record
- Defined in:
- lib/morpher/record.rb
Overview
Generator for struct a-like wrappers
Constant Summary collapse
- DEFAULTS =
{ required: EMPTY_HASH, optional: EMPTY_HASH }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#included(host) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Class Method Details
.new(**attributes) ⇒ Object
13 14 15 |
# File 'lib/morpher/record.rb', line 13 def self.new(**attributes) super(DEFAULTS.merge(attributes)) end |
Instance Method Details
#included(host) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/morpher/record.rb', line 19 def included(host) optional = optional() optional_transform = transform(optional) required = required() required_transform = transform(required) host.class_eval do include Adamantium::Flat, Anima.new(*(required.keys + optional.keys)) const_set( :TRANSFORM, Transform::Sequence.new( [ Transform::Primitive.new(Hash), Transform::Hash::Symbolize.new, Transform::Hash.new( required: required_transform, optional: optional_transform ), Transform::Success.new(public_method(:new)) ] ) ) end end |