Class: GraphdocRuby::Graphdoc

Inherits:
Object
  • Object
show all
Defined in:
lib/graphdoc-ruby/graphdoc.rb

Instance Method Summary collapse

Constructor Details

#initialize(output:, endpoint:, overwrite:, executable:, mtime:, query: {}, context: {}) ⇒ Graphdoc

Returns a new instance of Graphdoc.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphdoc-ruby/graphdoc.rb', line 6

def initialize(output:, endpoint:, overwrite:, executable:, mtime:, query: {}, context: {})
  @endpoint = endpoint
  @executable = executable
  @overwrite = overwrite
  @mtime = mtime

  @output_html = File.join(output, 'index.html')
  @options = ['--output', output]
  @options += ['--force'] if overwrite

  if query && !query.empty?
    query.each do |key_value|
      @options += ['--query', key_value.join('=')]
    end
  end

  if context && !context.empty?
    context.each do |key_value|
      @options += ['--header', key_value.join(': ')]
    end
  end
end

Instance Method Details

#generate_document!Object



29
30
31
32
33
34
# File 'lib/graphdoc-ruby/graphdoc.rb', line 29

def generate_document!
  return if generated?

  message, status = Open3.capture2e(*command)
  raise "Command failed. (#{command}) '#{message}'" unless status.success?
end