Class: DocgenAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/docgen_adapter.rb,
lib/docgen_adapter/version.rb,
lib/docgen_adapter/configuration.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
'1.3.1'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, doc_id:, debug: false, open: false, pdf: nil) ⇒ DocgenAdapter

Returns a new instance of DocgenAdapter.



7
8
9
10
11
12
13
14
15
16
# File 'lib/docgen_adapter.rb', line 7

def initialize(type:, doc_id:, debug: false, open: false, pdf: nil)
  # аргументы сервиса
  @type = type
  @doc_id = doc_id
  @debug = debug
  @open = Rails.env.development? && open
  @pdf = pdf
  @file_extension = pdf ? 'pdf' : @type
  @task_id = SecureRandom.uuid
end

Class Method Details

.configObject



14
15
16
# File 'lib/docgen_adapter/configuration.rb', line 14

def self.config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



9
10
11
12
# File 'lib/docgen_adapter/configuration.rb', line 9

def self.configure
  yield(config)
  config
end

Instance Method Details

#generate(params = {}) ⇒ Object

выполнение генерации документа



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/docgen_adapter.rb', line 19

def generate(params = {})
  @files = handle_files(params)
  @task_params = build_task_params(params)

  # отображение параметров для проверки
  puts JSON.pretty_generate(JSON.parse(@task_params)) if @debug

  # подписка ка канал и ожидание сообщений в другом потоке
  Thread.new { subscribe_and_listen }

  # ожидание
  sleep(0.7)

  # отправка сообщения с заданием
  redis.publish('TASKS', @task_params)

  # ожидание
  sleep(0.7)

  # отправка файлов при наличии
  @files.each do |file|
    redis.publish("files-#{@task_id}", file[:content])
    sleep(0.7)
  end

  # путь до сгенерированного файла в ответе
  filename
end