Class: Decidim::AttributeObject::TypeResolver

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/lib/decidim/attribute_object/type_resolver.rb

Overview

This resolves the ActiveModel::Attributes types from the Decidim’s own type definitions format inspired by Virtus.

Instance Method Summary collapse

Instance Method Details

#exists?(type) ⇒ Boolean



29
30
31
# File 'decidim-core/lib/decidim/attribute_object/type_resolver.rb', line 29

def exists?(type)
  ActiveModel::Type.registry.send(:registrations).has_key?(type)
end

#resolve(type, **options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'decidim-core/lib/decidim/attribute_object/type_resolver.rb', line 11

def resolve(type, **options)
  case type
  when Symbol, ActiveModel::Type::Value
    {
      type:,
      options:
    }
  when Class
    resolve_class(type, **options)
  when Hash
    resolve_hash(type, **options)
  when Array
    resolve_array(type, **options)
  else
    resolve_default(type, **options)
  end
end