Class: GraphdocRuby::Config

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

Defined Under Namespace

Classes: InvalidConfiguration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/graphdoc-ruby/config.rb', line 51

def initialize
  self.endpoint = nil
  self.executable_path = Bundler.which('graphdoc')
  self.output_directory = default_output_directory
  self.overwrite = true
  self.run_time_generation = true
  self.schema_name = nil
  self.graphql_context = -> {}
  self.graphql_query = -> {}

  @use_temporary_output_directory = true
  @mtime = Time.now
end

Instance Attribute Details

#endpointObject

Required: <String> GraphQL endpoint url or dumped schema.json path.



11
12
13
# File 'lib/graphdoc-ruby/config.rb', line 11

def endpoint
  @endpoint
end

#executable_pathObject

Optional: <String> Executable path of ‘graphdoc`. (default: `Bundler.which(’graphdoc’)‘)



16
17
18
# File 'lib/graphdoc-ruby/config.rb', line 16

def executable_path
  @executable_path
end

#graphql_contextObject

Optional: <Proc> Context of your graphql. (default: -> {})



36
37
38
# File 'lib/graphdoc-ruby/config.rb', line 36

def graphql_context
  @graphql_context
end

#graphql_queryObject

Optional: <Proc> Query of your graphql. (default: -> {})



41
42
43
# File 'lib/graphdoc-ruby/config.rb', line 41

def graphql_query
  @graphql_query
end

#mtimeObject (readonly)

no doc



49
50
51
# File 'lib/graphdoc-ruby/config.rb', line 49

def mtime
  @mtime
end

#output_directoryObject

Optional: <String> Output path for ‘graphdoc`. If you disabled run_time_generation, this value must be customized. (default: `File.join(Dir.mktmpdir, ’graphdoc’)‘)



21
22
23
# File 'lib/graphdoc-ruby/config.rb', line 21

def output_directory
  @output_directory
end

#overwriteObject

Optional: <Boolean> Overwrite files if generated html already exist. (default: true)



26
27
28
# File 'lib/graphdoc-ruby/config.rb', line 26

def overwrite
  @overwrite
end

#run_time_generationObject

Optional: <Boolean> Generate html with graphdoc on the first access. (default: true)



31
32
33
# File 'lib/graphdoc-ruby/config.rb', line 31

def run_time_generation
  @run_time_generation
end

#schema_nameObject

Optional: <String> Schema name of your graphql-ruby. It is necessary when generating schema.json. (default: nil)



46
47
48
# File 'lib/graphdoc-ruby/config.rb', line 46

def schema_name
  @schema_name
end

Instance Method Details

#assert_configuration!Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/graphdoc-ruby/config.rb', line 84

def assert_configuration!
  unless endpoint
    raise InvalidConfiguration, "(endpoint: '#{endpoint}') must be GraphQL endpoint url or dumped schema.json path."
  end

  if @use_temporary_output_directory && !run_time_generation
    raise InvalidConfiguration, 'If you disabled run_time_generation, static `output_directory` must be set.'
  end

  unless File.executable?(executable_path)
    raise InvalidConfiguration, '`graphdoc` not found. Please install graphdoc (npm install -g @2fd/graphdoc)'
  end
end

#evaluate_graphql_contextObject



74
75
76
77
# File 'lib/graphdoc-ruby/config.rb', line 74

def evaluate_graphql_context
  hash = self.graphql_context.call
  hash if hash.is_a?(Hash)
end

#evaluate_graphql_queryObject



79
80
81
82
# File 'lib/graphdoc-ruby/config.rb', line 79

def evaluate_graphql_query
  hash = self.graphql_query.call
  hash if hash.is_a?(Hash)
end