module JsonbAccessor::Macro
def build_class_namespace(class_name)
def build_class_namespace(class_name) class_name = class_name.gsub(CONSTANT_SEPARATOR, "") if JsonbAccessor.constants.any? { |c| c.to_s == class_name } class_namespace = JsonbAccessor.const_get(class_name) else class_namespace = Module.new JsonbAccessor.const_set(class_name, class_namespace) end class_namespace end
def group_attributes(value_fields, typed_fields)
def group_attributes(value_fields, typed_fields) value_fields_hash = process_value_fields(value_fields) typed_fields.each_with_object(nested: {}, typed: value_fields_hash) do |(attribute_name, type_or_nested), grouped_attributes| group = type_or_nested.is_a?(Hash) ? grouped_attributes[:nested] : grouped_attributes[:typed] group[attribute_name] = type_or_nested end end
def process_value_fields(value_fields)
def process_value_fields(value_fields) value_fields.each_with_object({}) do |value_field, hash_for_value_fields| hash_for_value_fields[value_field] = :value end end