Class: Trax::Model::Attributes::Types::UuidArray

Inherits:
Trax::Model::Attributes::Type show all
Defined in:
lib/trax/model/attributes/types/uuid_array.rb

Defined Under Namespace

Classes: Attribute, TypeCaster, Value

Class Method Summary collapse

Methods inherited from Trax::Model::Attributes::Type

inherited

Class Method Details

.define_attribute(klass, attribute_name, **options, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/trax/model/attributes/types/uuid_array.rb', line 6

def self.define_attribute(klass, attribute_name, **options, &block)
  klass_name = "#{klass.fields_module.name.underscore}/#{attribute_name}".camelize
  attribute_klass = if options.key?(:class_name)
    options[:class_name].constantize
  else
    ::Trax::Core::NamedClass.new(klass_name, Value, :parent_definition => klass, &block)
  end

  attribute_klass.element_class = options[:of] if options.has_key?(:of)
  options.has_key?(:default) ? self.default_value_for(attribute_name, options[:default]) : []
  klass.attribute(attribute_name, typecaster_klass.new(target_klass: attribute_klass))
end