Class: Decidim::AttributeObject::TypeResolver
- Inherits:
-
Object
- Object
- Decidim::AttributeObject::TypeResolver
- Defined in:
- 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 32 33 |
# File '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 'lib/decidim/attribute_object/type_resolver.rb', line 11 def resolve(type, **) case type when Symbol, ActiveModel::Type::Value { type: type, options: } when Class resolve_class(type, **) when Hash resolve_hash(type, **) when Array resolve_array(type, **) else resolve_default(type, **) end end |