Class: KManager::DocumentFactory

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/k_manager/document_factory.rb

Overview

Factories for creating common DSL documents quickly

Example:

KManager.csv(file: 'somepath/somefile.csv') do
  load
end

Instance Method Summary collapse

Instance Method Details

#action(key = nil, **opts, &block) ⇒ Object

Create a KDoc::Model instance



15
16
17
18
19
# File 'lib/k_manager/document_factory.rb', line 15

def action(key = nil, **opts, &block)
  document = new_document(KDoc::Action, key, **opts, &block)

  attach_to_current_resource(document, change_content_type: :ruby)
end

#csv(key = nil, **opts, &block) ⇒ Object

Create a KDoc::CsvDoc instance



29
30
31
32
33
34
35
# File 'lib/k_manager/document_factory.rb', line 29

def csv(key = nil, **opts, &block)
  document = new_document(KDoc::CsvDoc, key, **opts, &block)

  attach_to_current_resource(document, change_content_type: :dsl)
rescue StandardError => e
  log.error(e)
end

#json(key = nil, **opts, &block) ⇒ Object

Create a KDoc::JsonDoc instance



38
39
40
41
42
43
44
# File 'lib/k_manager/document_factory.rb', line 38

def json(key = nil, **opts, &block)
  document = new_document(KDoc::JsonDoc, key, **opts, &block)

  attach_to_current_resource(document, change_content_type: :dsl)
rescue StandardError => e
  log.error(e)
end

#model(key = nil, **opts, &block) ⇒ Object

Create a KDoc::Model instance



22
23
24
25
26
# File 'lib/k_manager/document_factory.rb', line 22

def model(key = nil, **opts, &block)
  document = new_document(KDoc::Model, key, **opts, &block)

  attach_to_current_resource(document, change_content_type: :dsl)
end

#yaml(key = nil, **opts, &block) ⇒ Object

Create a KDoc::YamlDoc instance



47
48
49
50
51
52
53
# File 'lib/k_manager/document_factory.rb', line 47

def yaml(key = nil, **opts, &block)
  document = new_document(KDoc::YamlDoc, key, **opts, &block)

  attach_to_current_resource(document, change_content_type: :dsl)
rescue StandardError => e
  log.error(e)
end