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
-
#access ⇒ Array<Symbol>
Returns the normalized access modes for the attribute (e.g., [:read, :write]).
-
#full_access? ⇒ Boolean
Whether the attribute is both readable and writeable.
-
#ignore? ⇒ Boolean
Whether the attribute is ignored completely.
-
#readable? ⇒ Boolean
Whether the attribute should be included during serialization.
-
#skip_deserialization? ⇒ Boolean
Whether the attribute should be skipped during deserialization.
-
#skip_serialization? ⇒ Boolean
Whether the attribute should be skipped during serialization.
-
#writeable? ⇒ Boolean
Whether the attribute should be accepted during deserialization.
Instance Method Details
#access ⇒ Array<Symbol>
Returns the normalized access modes for the attribute (e.g., [:read, :write]).
14 15 16 |
# File 'lib/castkit/attribute_extensions/access.rb', line 14 def access Array([:access]).map(&:to_sym) end |
#full_access? ⇒ Boolean
Whether the attribute is both readable and writeable.
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.
60 61 62 |
# File 'lib/castkit/attribute_extensions/access.rb', line 60 def ignore? [:ignore] end |
#readable? ⇒ Boolean
Whether the attribute should be included during serialization.
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.
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.
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.
30 31 32 |
# File 'lib/castkit/attribute_extensions/access.rb', line 30 def writeable? access.include?(:write) && !composite? end |