Class: GraphdocRuby::Config
- Inherits:
-
Object
- Object
- GraphdocRuby::Config
- Defined in:
- lib/graphdoc-ruby/config.rb
Defined Under Namespace
Classes: InvalidConfiguration
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Required: <String> GraphQL endpoint url or dumped schema.json path.
-
#executable_path ⇒ Object
Optional: <String> Executable path of ‘graphdoc`.
-
#graphql_context ⇒ Object
Optional: <Proc> Context of your graphql.
-
#graphql_query ⇒ Object
Optional: <Proc> Query of your graphql.
-
#mtime ⇒ Object
readonly
no doc.
-
#output_directory ⇒ Object
Optional: <String> Output path for ‘graphdoc`.
-
#overwrite ⇒ Object
Optional: <Boolean> Overwrite files if generated html already exist.
-
#run_time_generation ⇒ Object
Optional: <Boolean> Generate html with graphdoc on the first access.
-
#schema_name ⇒ Object
Optional: <String> Schema name of your graphql-ruby.
Instance Method Summary collapse
- #assert_configuration! ⇒ Object
- #evaluate_graphql_context ⇒ Object
- #evaluate_graphql_query ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
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
#endpoint ⇒ Object
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_path ⇒ Object
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_context ⇒ Object
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_query ⇒ Object
Optional: <Proc> Query of your graphql. (default: -> {})
41 42 43 |
# File 'lib/graphdoc-ruby/config.rb', line 41 def graphql_query @graphql_query end |
#mtime ⇒ Object (readonly)
no doc
49 50 51 |
# File 'lib/graphdoc-ruby/config.rb', line 49 def mtime @mtime end |
#output_directory ⇒ Object
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 |
#overwrite ⇒ Object
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_generation ⇒ Object
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_name ⇒ Object
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_context ⇒ Object
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_query ⇒ Object
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 |