Class: Bronze::Entities::Attributes::Builder
- Inherits:
-
Object
- Object
- Bronze::Entities::Attributes::Builder
- Defined in:
- lib/bronze/entities/attributes/builder.rb
Overview
Service class to define attributes on an entity.
Constant Summary collapse
- VALID_OPTIONS =
Provides a list of the valid options for the attribute_options parameter for Builder#build.
%w[ allow_nil default default_transform foreign_key primary_key read_only transform ].map(&:freeze).freeze
Instance Attribute Summary collapse
-
#entity_class ⇒ Class
readonly
The entity class on which attributes will be defined.
Class Method Summary collapse
-
.attribute_transform(type, transform) ⇒ Object
Registers a transform as the default transform for attributes with the specified type or a subtype of the specified type.
Instance Method Summary collapse
-
#build(attribute_name, attribute_type, attribute_options = {}) ⇒ Attributes::Metadata
Defines an attribute on the entity class.
-
#initialize(entity_class) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(entity_class) ⇒ Builder
Returns a new instance of Builder.
76 77 78 |
# File 'lib/bronze/entities/attributes/builder.rb', line 76 def initialize(entity_class) @entity_class = entity_class end |
Instance Attribute Details
#entity_class ⇒ Class (readonly)
Returns the entity class on which attributes will be defined.
81 82 83 |
# File 'lib/bronze/entities/attributes/builder.rb', line 81 def entity_class @entity_class end |
Class Method Details
.attribute_transform(type, transform) ⇒ Object
Registers a transform as the default transform for attributes with the specified type or a subtype of the specified type.
This default is not retroactive - any attributes already defined will use their existing default transform, if any. If more than one registered transform has a matching type, the most recently defined transform will be used.
44 45 46 |
# File 'lib/bronze/entities/attributes/builder.rb', line 44 def attribute_transform(type, transform) (@attribute_transforms ||= {})[type] = transform end |
Instance Method Details
#build(attribute_name, attribute_type, attribute_options = {}) ⇒ Attributes::Metadata
Defines an attribute on the entity class.
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/bronze/entities/attributes/builder.rb', line 131 def build(attribute_name, attribute_type, = {}) validate_attribute_name(attribute_name) validate_attribute_opts() characterize( attribute_name, attribute_type, ) .tap { || define_property_methods() } end |