Class: Graphiti::Configuration
Instance Attribute Summary collapse
-
#before_sideload ⇒ Object
Returns the value of attribute before_sideload.
-
#cache_rendering ⇒ Object
writeonly
Sets the attribute cache_rendering.
-
#concurrency ⇒ Boolean
Concurrently fetch sideloads? Defaults to false OR if classes are cached (Rails-only).
-
#concurrency_max_threads ⇒ Integer
This number must be considered in accordance with the database connection pool size configured in
database.yml. -
#context_for_endpoint ⇒ Object
Returns the value of attribute context_for_endpoint.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#debug_models ⇒ Object
Returns the value of attribute debug_models.
-
#raise_on_missing_sideload ⇒ Boolean
Should we raise when the client requests a relationship not defined on the server? Defaults to true.
-
#raise_on_missing_sidepost ⇒ Object
Returns the value of attribute raise_on_missing_sidepost.
-
#respond_to ⇒ Object
Returns the value of attribute respond_to.
- #schema_path ⇒ Object
-
#uri_decoder ⇒ Object
Returns the value of attribute uri_decoder.
Instance Method Summary collapse
- #cache_rendering? ⇒ Boolean
-
#coerce_flag(val) ⇒ Object
every value comes back from ENV as a string and "false" is truthy.
-
#initialize ⇒ Configuration
constructor
private
Set defaults.
- #links_on_demand ⇒ Object
- #links_on_demand=(val) ⇒ Object
- #pagination_links ⇒ Object
- #pagination_links=(val) ⇒ Object
- #pagination_links_on_demand ⇒ Object
- #pagination_links_on_demand=(val) ⇒ Object
- #typecast_reads ⇒ Object
- #typecast_reads=(val) ⇒ Object
- #with_option(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set defaults
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/graphiti/configuration.rb', line 38 def initialize @raise_on_missing_sideload = true @concurrency = false @concurrency_max_threads = 4 @respond_to = [:json, :jsonapi, :xml] @raise_on_missing_sidepost = true @cache_rendering = false self.debug = ENV.fetch("GRAPHITI_DEBUG", true) self.debug_models = ENV.fetch("GRAPHITI_DEBUG_MODELS", false) @uri_decoder = infer_uri_decoder end |
Instance Attribute Details
#before_sideload ⇒ Object
Returns the value of attribute before_sideload.
28 29 30 |
# File 'lib/graphiti/configuration.rb', line 28 def before_sideload @before_sideload end |
#cache_rendering=(value) ⇒ Object (writeonly)
Sets the attribute cache_rendering
34 35 36 |
# File 'lib/graphiti/configuration.rb', line 34 def cache_rendering=(value) @cache_rendering = value end |
#concurrency ⇒ Boolean
Returns Concurrently fetch sideloads? Defaults to false OR if classes are cached (Rails-only).
9 10 11 |
# File 'lib/graphiti/configuration.rb', line 9 def concurrency @concurrency end |
#concurrency_max_threads ⇒ Integer
This number must be considered in accordance with the database
connection pool size configured in database.yml. The connection
pool should be large enough to accommodate both the foreground
threads (ie. web server or job worker threads) and background
threads. For each process, Graphiti will create one global
executor that uses this many threads to sideload resources
asynchronously. Thus, the pool size should be at least
thread_count + concurrency_max_threads + 1. For example, if your
web server has a maximum of 3 threads, and
concurrency_max_threads is set to 4, then your pool size should
be at least 8.
23 24 25 |
# File 'lib/graphiti/configuration.rb', line 23 def concurrency_max_threads @concurrency_max_threads end |
#context_for_endpoint ⇒ Object
Returns the value of attribute context_for_endpoint.
26 27 28 |
# File 'lib/graphiti/configuration.rb', line 26 def context_for_endpoint @context_for_endpoint end |
#debug ⇒ Object
Returns the value of attribute debug.
30 31 32 |
# File 'lib/graphiti/configuration.rb', line 30 def debug @debug end |
#debug_models ⇒ Object
Returns the value of attribute debug_models.
30 31 32 |
# File 'lib/graphiti/configuration.rb', line 30 def debug_models @debug_models end |
#raise_on_missing_sideload ⇒ Boolean
Returns Should we raise when the client requests a relationship not defined on the server? Defaults to true.
6 7 8 |
# File 'lib/graphiti/configuration.rb', line 6 def raise_on_missing_sideload @raise_on_missing_sideload end |
#raise_on_missing_sidepost ⇒ Object
Returns the value of attribute raise_on_missing_sidepost.
27 28 29 |
# File 'lib/graphiti/configuration.rb', line 27 def raise_on_missing_sidepost @raise_on_missing_sidepost end |
#respond_to ⇒ Object
Returns the value of attribute respond_to.
25 26 27 |
# File 'lib/graphiti/configuration.rb', line 25 def respond_to @respond_to end |
#schema_path ⇒ Object
61 62 63 |
# File 'lib/graphiti/configuration.rb', line 61 def schema_path @schema_path ||= raise("No schema_path defined! Set Graphiti.config.schema_path to save your schema.") end |
#uri_decoder ⇒ Object
Returns the value of attribute uri_decoder.
31 32 33 |
# File 'lib/graphiti/configuration.rb', line 31 def uri_decoder @uri_decoder end |
Instance Method Details
#cache_rendering? ⇒ Boolean
51 52 53 54 55 56 57 58 59 |
# File 'lib/graphiti/configuration.rb', line 51 def cache_rendering? use_caching = @cache_rendering && Graphiti.cache.respond_to?(:fetch) use_caching.tap do |use| if @cache_rendering && !Graphiti.cache&.respond_to?(:fetch) raise "You must configure a cache store in order to use cache_rendering. Set Graphiti.cache = Rails.cache, for example." end end end |
#coerce_flag(val) ⇒ Object
every value comes back from ENV as a string and "false" is truthy
76 77 78 79 80 |
# File 'lib/graphiti/configuration.rb', line 76 def coerce_flag(val) return false if ["false", "0", ""].include?(val.to_s.strip.downcase) !!val end |
#links_on_demand ⇒ Object
98 99 100 |
# File 'lib/graphiti/configuration.rb', line 98 def links_on_demand Resource.relationship_links == :on_demand end |
#links_on_demand=(val) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/graphiti/configuration.rb', line 102 def links_on_demand=(val) if val Resource.relationship_links = :on_demand elsif Resource.relationship_links == :on_demand Resource.relationship_links = true end end |
#pagination_links ⇒ Object
110 111 112 |
# File 'lib/graphiti/configuration.rb', line 110 def pagination_links Resource.page_links == true end |
#pagination_links=(val) ⇒ Object
114 115 116 117 118 |
# File 'lib/graphiti/configuration.rb', line 114 def pagination_links=(val) return if Resource.page_links == :on_demand Resource.page_links = !!val end |
#pagination_links_on_demand ⇒ Object
120 121 122 |
# File 'lib/graphiti/configuration.rb', line 120 def pagination_links_on_demand Resource.page_links == :on_demand end |
#pagination_links_on_demand=(val) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/graphiti/configuration.rb', line 124 def pagination_links_on_demand=(val) if val Resource.page_links = :on_demand elsif Resource.page_links == :on_demand Resource.page_links = false end end |
#typecast_reads ⇒ Object
90 91 92 |
# File 'lib/graphiti/configuration.rb', line 90 def typecast_reads Resource.typecast_reads end |
#typecast_reads=(val) ⇒ Object
94 95 96 |
# File 'lib/graphiti/configuration.rb', line 94 def typecast_reads=(val) Resource.typecast_reads = val end |
#with_option(key, value) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/graphiti/configuration.rb', line 82 def with_option(key, value) original = send(key) send(:"#{key}=", value) yield ensure send(:"#{key}=", original) end |