Module: JSONAPIonify::Structure::Helpers::Validations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Objects::Base
- Defined in:
- lib/jsonapionify/structure/helpers/validations.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #allowed_type_map ⇒ Object
-
#permitted_key?(key) ⇒ Boolean
Instance Methods.
- #permitted_keys ⇒ Object
- #permitted_type_for?(key) ⇒ Boolean
- #permitted_types_for(key) ⇒ Object
- #required_key?(key) ⇒ Boolean
- #required_keys ⇒ Object
Instance Method Details
#allowed_type_map ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 263 def allowed_type_map self.class.allowed_type_map.dup.tap do |hash| wildcard_types = hash.delete('*') keys.each do |k| hash[k] ||= {} hash[k].deep_merge! wildcard_types end if wildcard_types.present? end end |
#permitted_key?(key) ⇒ Boolean
Instance Methods
231 232 233 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 231 def permitted_key?(key) !allow_only_permitted || permitted_keys.map(&:to_sym).include?(key.to_sym) end |
#permitted_keys ⇒ Object
259 260 261 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 259 def permitted_keys (*self.class.permitted_keys) end |
#permitted_type_for?(key) ⇒ Boolean
245 246 247 248 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 245 def permitted_type_for?(key) types = permitted_types_for(key) types.empty? || permitted_types_for(key).any? { |type| self[key].is_a? type } end |
#permitted_types_for(key) ⇒ Object
250 251 252 253 254 255 256 257 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 250 def permitted_types_for(key) = allowed_type_map[key] || {} .each_with_object([]) do |(, types), permitted_types| JSONAPIonify::Continuation.new(**).check(self) do permitted_types.concat types end end.uniq end |
#required_key?(key) ⇒ Boolean
235 236 237 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 235 def required_key?(key) required_keys.include? key end |
#required_keys ⇒ Object
239 240 241 242 243 |
# File 'lib/jsonapionify/structure/helpers/validations.rb', line 239 def required_keys self.class.required_keys.select do |_, | JSONAPIonify::Continuation.new(**).check(self) { true } end.keys end |