Module: Castkit::Ext::Attribute::Access

Included in:
Attribute
Defined in:
lib/castkit/ext/attribute/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



15
16
17
# File 'lib/castkit/ext/attribute/access.rb', line 15

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

#full_access?Boolean

Whether the attribute is both readable and writeable.

Returns:

  • (Boolean)


38
39
40
# File 'lib/castkit/ext/attribute/access.rb', line 38

def full_access?
  readable? && writeable?
end

#ignore?Boolean

Whether the attribute is ignored completely.

Returns:

  • (Boolean)


61
62
63
# File 'lib/castkit/ext/attribute/access.rb', line 61

def ignore?
  options[:ignore]
end

#readable?Boolean

Whether the attribute should be included during serialization.

Returns:

  • (Boolean)


22
23
24
# File 'lib/castkit/ext/attribute/access.rb', line 22

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

#skip_deserialization?Boolean

Whether the attribute should be skipped during deserialization.

Returns:

  • (Boolean)


54
55
56
# File 'lib/castkit/ext/attribute/access.rb', line 54

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)


47
48
49
# File 'lib/castkit/ext/attribute/access.rb', line 47

def skip_serialization?
  !readable? || ignore?
end

#writeable?Boolean

Whether the attribute should be accepted during deserialization.

Composite attributes are excluded from writeability.

Returns:

  • (Boolean)


31
32
33
# File 'lib/castkit/ext/attribute/access.rb', line 31

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