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
-
#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]).
15 16 17 |
# File 'lib/castkit/ext/attribute/access.rb', line 15 def access Array([:access]).map(&:to_sym) end |
#full_access? ⇒ Boolean
Whether the attribute is both readable and writeable.
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.
61 62 63 |
# File 'lib/castkit/ext/attribute/access.rb', line 61 def ignore? [:ignore] end |
#readable? ⇒ Boolean
Whether the attribute should be included during serialization.
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.
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.
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.
31 32 33 |
# File 'lib/castkit/ext/attribute/access.rb', line 31 def writeable? access.include?(:write) && !composite? end |