Module: Parse::API::Config
- Included in:
- Client
- Defined in:
- lib/parse/api/config.rb
Overview
Defines the Config interface for the Parse REST API
Instance Attribute Summary collapse
-
#config ⇒ Hash
Return the configuration hash for the configured application for this client.
-
#master_key_only ⇒ Hash{String=>Boolean}
Return the masterKeyOnly flag map for the application configuration.
Instance Method Summary collapse
-
#config! ⇒ Hash
Force fetch the application configuration hash.
-
#config_entries(master: false) ⇒ Hash{String=>Hash}
Return every config entry zipped with its masterKeyOnly trait.
-
#update_config(params, master_key_only: nil) ⇒ Boolean
Update the application configuration.
Instance Attribute Details
#config ⇒ Hash
Return the configuration hash for the configured application for this client.
This method caches the configuration after the first time it is fetched.
The accompanying masterKeyOnly map (if returned by the server) is cached
alongside it and exposed via #master_key_only.
11 |
# File 'lib/parse/api/config.rb', line 11 attr_writer :config |
#master_key_only ⇒ Hash{String=>Boolean}
Return the masterKeyOnly flag map for the application configuration.
Keys map to true when the corresponding config param is only readable
by master-key clients. Lazily triggers a config fetch on first access.
15 |
# File 'lib/parse/api/config.rb', line 15 attr_writer :master_key_only |
Instance Method Details
#config! ⇒ Hash
Returns force fetch the application configuration hash.
21 22 23 24 25 |
# File 'lib/parse/api/config.rb', line 21 def config! @config = nil @master_key_only = nil self.config end |
#config_entries(master: false) ⇒ Hash{String=>Hash}
Return every config entry zipped with its masterKeyOnly trait.
Pass master: true to include keys whose masterKeyOnly flag is true;
the default master: false filters those entries out, matching what a
non-master-key client would actually observe. Each entry has the shape
{ value: ..., master_key_only: Boolean }. This is a client-side
filter on the already-cached config — it does NOT re-request the
config. When the connection is not authenticated with the master key,
Parse Server has already stripped master-key-only entries before the
response reaches the cache, so master: true has nothing extra to
surface in that case.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/parse/api/config.rb', line 58 def config_entries(master: false) config if @config.nil? return {} if @config.nil? flags = @master_key_only || {} @config.each_with_object({}) do |(key, value), out| is_master_only = flags[key] == true next if is_master_only && !master out[key] = { value: value, master_key_only: is_master_only } end end |
#update_config(params, master_key_only: nil) ⇒ Boolean
Update the application configuration.
Pass master_key_only: to additionally mark (or unmark) which keys are
only readable by master-key clients. Parse Server merges this map into
the existing flags; unspecified keys keep their current flag. Note that
Parse Server rejects masterKeyOnly entries for keys that do not exist
in params (either in this PUT body or already stored).
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/parse/api/config.rb', line 91 def update_config(params, master_key_only: nil) body = { params: params } unless master_key_only.nil? body[:masterKeyOnly] = master_key_only # Parse Server (9.x) rejects PUT /parse/config when masterKeyOnly # references a key that is not present in the request's params # payload, EVEN IF the key already exists in stored config. The # SDK absorbs that constraint by backfilling any flag-only keys # from the cached @config so flag-only updates round-trip cleanly. # Without this, `update_config({}, master_key_only: {foo: false})` # would always fail with a server-side 400 even after foo was # previously persisted. if @config.is_a?(Hash) master_key_only.each_key do |k| ks = k.to_s next if body[:params].key?(ks) || body[:params].key?(k) cached = @config[ks] body[:params][ks] = cached unless cached.nil? end end end response = request :put, CONFIG_PATH, body: body return false if response.error? result = response.result["result"] if result @config.merge!(params) if @config.present? if master_key_only.is_a?(Hash) && @master_key_only.is_a?(Hash) @master_key_only.merge!(master_key_only.transform_keys(&:to_s)) end end result end |