Class: Sanity::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sanity/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_versionString

Returns Sanity’s api version.

Returns:

  • (String)

    Sanity’s api version



12
13
14
# File 'lib/sanity/configuration.rb', line 12

def api_version
  @api_version
end

#datasetString

Returns Sanity’s dataset.

Returns:

  • (String)

    Sanity’s dataset



9
10
11
# File 'lib/sanity/configuration.rb', line 9

def dataset
  @dataset
end

#project_idString

Returns Sanity’s project id.

Returns:

  • (String)

    Sanity’s project id



6
7
8
# File 'lib/sanity/configuration.rb', line 6

def project_id
  @project_id
end

#tokenString

Returns Sanity’s api token.

Returns:

  • (String)

    Sanity’s api token



15
16
17
# File 'lib/sanity/configuration.rb', line 15

def token
  @token
end

#use_cdnBoolean

Returns whether to use Sanity’s cdn api.

Returns:

  • (Boolean)

    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_subdomainString

Returns Api subdomain based on use_cdn flag.

Returns:

  • (String)

    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_hObject



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