Class: Sanity::Configuration
- Inherits:
-
Object
- Object
- Sanity::Configuration
- Defined in:
- lib/sanity/configuration.rb
Instance Attribute Summary collapse
-
#api_version ⇒ String
Sanity’s api version.
-
#dataset ⇒ String
Sanity’s dataset.
-
#project_id ⇒ String
Sanity’s project id.
-
#token ⇒ String
Sanity’s api token.
-
#use_cdn ⇒ Boolean
Whether to use Sanity’s cdn api.
Instance Method Summary collapse
-
#api_subdomain ⇒ String
Api subdomain based on use_cdn flag.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
20 21 22 23 24 25 26 |
# File 'lib/sanity/configuration.rb', line 20 def initialize @project_id = ENV.fetch("SANITY_PROJECT_ID", "") @dataset = ENV.fetch("SANITY_DATASET", "") @api_version = ENV.fetch("SANITY_API_VERSION", "") @token = ENV.fetch("SANITY_TOKEN", "") @use_cdn = ENV.fetch("SANITY_USE_CDN", false) == "true" end |
Instance Attribute Details
#api_version ⇒ String
Returns Sanity’s api version.
12 13 14 |
# File 'lib/sanity/configuration.rb', line 12 def api_version @api_version end |
#dataset ⇒ String
Returns Sanity’s dataset.
9 10 11 |
# File 'lib/sanity/configuration.rb', line 9 def dataset @dataset end |
#project_id ⇒ String
Returns Sanity’s project id.
6 7 8 |
# File 'lib/sanity/configuration.rb', line 6 def project_id @project_id end |
#token ⇒ String
Returns Sanity’s api token.
15 16 17 |
# File 'lib/sanity/configuration.rb', line 15 def token @token end |
#use_cdn ⇒ Boolean
Returns whether to use Sanity’s cdn api.
18 19 20 |
# File 'lib/sanity/configuration.rb', line 18 def use_cdn @use_cdn end |
Instance Method Details
#api_subdomain ⇒ String
Returns Api subdomain based on use_cdn flag.
29 30 31 |
# File 'lib/sanity/configuration.rb', line 29 def api_subdomain use_cdn ? "apicdn" : "api" end |
#to_h ⇒ Object
33 34 35 36 37 |
# File 'lib/sanity/configuration.rb', line 33 def to_h instance_variables.each_with_object({}) do |var, obj| obj[var.to_s.delete("@").to_sym] = instance_variable_get(var) end end |