Class: Decidim::Attributes::Object

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/decidim/attributes/object.rb

Overview

Custom attributes value to represent an Object.

Direct Known Subclasses

Model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(primitive: ::Object) ⇒ Object

Returns a new instance of Object.



9
10
11
# File 'lib/decidim/attributes/object.rb', line 9

def initialize(primitive: ::Object)
  @primitive = primitive
end

Instance Attribute Details

#primitiveObject (readonly)

Returns the value of attribute primitive.



7
8
9
# File 'lib/decidim/attributes/object.rb', line 7

def primitive
  @primitive
end

Instance Method Details

#typeObject

:nodoc:



13
14
15
# File 'lib/decidim/attributes/object.rb', line 13

def type # :nodoc:
  :object
end

#validate_nested?Boolean

The nested validator should be only added for those attributes that inherit from the AttributeObject::Model type. Otherwise this would be also added e.g. for ActiveRecord objects which would cause unexpected validation errors.

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/decidim/attributes/object.rb', line 21

def validate_nested?
  return false unless primitive.is_a?(Class)

  (primitive < Decidim::AttributeObject::Model) == true
end