Module: Castkit::AttributeExtensions::Access

Included in:
Castkit::Attribute
Defined in:
lib/castkit/attribute_extensions/access.rb

Overview

Provides access control helpers for attributes.

These helpers determine whether an attribute is readable, writeable, or should be included during serialization/deserialization based on the configured ‘:access` and `:ignore` options.

Instance Method Summary collapse

Instance Method Details

#accessArray<Symbol>

Returns the normalized access modes for the attribute (e.g., [:read, :write]).

Returns:

  • (Array<Symbol>)

    list of access symbols



14
15
16
# File 'lib/castkit/attribute_extensions/access.rb', line 14

def access
  Array(options[:access]).map(&:to_sym)
end

#full_access?Boolean

Whether the attribute is both readable and writeable.

Returns:

  • (Boolean)


37
38
39
# File 'lib/castkit/attribute_extensions/access.rb', line 37

def full_access?
  readable? && writeable?
end

#ignore?Boolean

Whether the attribute is ignored completely.

Returns:

  • (Boolean)


60
61
62
# File 'lib/castkit/attribute_extensions/access.rb', line 60

def ignore?
  options[:ignore]
end

#readable?Boolean

Whether the attribute should be included during serialization.

Returns:

  • (Boolean)


21
22
23
# File 'lib/castkit/attribute_extensions/access.rb', line 21

def readable?
  access.include?(:read)
end

#skip_deserialization?Boolean

Whether the attribute should be skipped during deserialization.

Returns:

  • (Boolean)


53
54
55
# File 'lib/castkit/attribute_extensions/access.rb', line 53

def skip_deserialization?
  !writeable?
end

#skip_serialization?Boolean

Whether the attribute should be skipped during serialization.

This is true if it’s not readable or is marked as ignored.

Returns:

  • (Boolean)


46
47
48
# File 'lib/castkit/attribute_extensions/access.rb', line 46

def skip_serialization?
  !readable? || ignore?
end

#writeable?Boolean

Whether the attribute should be accepted during deserialization.

Composite attributes are excluded from writeability.

Returns:

  • (Boolean)


30
31
32
# File 'lib/castkit/attribute_extensions/access.rb', line 30

def writeable?
  access.include?(:write) && !composite?
end