require_relative "../models" module Alphadex def self.add_bookmark(url:, title:, note:, tags:) fail "url already exists" unless Url.where(url:).empty? DB.transaction do entity = Entity.create entity.url = Url.new(url:) entity.title = Title.new(title:) if title entity.add_note(text: note) tags.map { Tag.find_or_create(name: _1) }.each do |tag| entity.add_tag(tag) end entity end end end