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

Returns:

  • (Boolean)


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

def exists?(type)
  # This needs to be changed after upgrade to Rails 7.0 as follows:
  # ActiveModel::Type.registry.send(:registrations).has_key?(type)
  ActiveModel::Type.registry.send(:registrations).any? { |t| t.send(:name) == 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