module KManager::CreateDocument
Public Instance Methods
attach_to_resource(document, change_resource_type: :dsl)
click to toggle source
# File lib/k_manager/create_document.rb, line 12 def attach_to_resource(document, change_resource_type: :dsl) KManager.target_resource&.attach_document(document, change_resource_type: :dsl) document end
model(key = nil, **opts)
click to toggle source
# File lib/k_manager/create_document.rb, line 5 def model(key = nil, **opts) opts = { key: key }.merge(opts) unless key.nil? document = new_document(KManager::Documents::ModelDocument, **opts) attach_to_resource(document, change_resource_type: :dsl) end
new_document(klass, **opts)
click to toggle source
Create an instance of a document
@param [Class<DocumentTaggable>] klass type of document to create
# File lib/k_manager/create_document.rb, line 20 def new_document(klass, **opts) key = KManager.target_resource.documents.length.zero? ? KManager.target_resource.infer_key : nil opts = { resource: KManager.target_resource, key: key }.merge(opts) klass.new(**opts) end