class Realm::Struct
Public Class Methods
merge(attributes)
click to toggle source
# File lib/realm/struct.rb, line 28 def merge(attributes) clone.attributes(attributes) end
to_dry_schema(type: :schema)
click to toggle source
# File lib/realm/struct.rb, line 9 def to_dry_schema(type: :schema) # rubocop:disable Metrics/AbcSize keys = schema.type.keys Dry::Schema.send(schema_type_to_method(type)) do keys.each do |key| param = key.required? ? required(key.name) : optional(key.name) if key.type.constructor_type == Dry::Types::Array::Constructor # array type member = key.type.member param.array(member.respond_to?(:to_dry_schema) ? member.to_dry_schema(type: type) : member) elsif key.respond_to?(:to_dry_schema) # realm struct param.hash(key.to_dry_schema(type: type)) else param.send(key.required? ? :filled : :maybe, key.type) end end end end
Private Class Methods
schema_type_to_method(type)
click to toggle source
# File lib/realm/struct.rb, line 34 def schema_type_to_method(type) case type when :schema :define when :params :Params when :json :JSON else raise "Not supported schema type #{type}" end end