Sha256: d06429f671da72ff388d6306ba4bad2fb65753d24dda7f84086ab44c1d9add21

Contents?: true

Size: 1.89 KB

Versions: 8

Compression:

Stored size: 1.89 KB

Contents

# https://robots.thoughtbot.com/mygem-configure-block
module Graphiti
  class Configuration
    # @return [Boolean] Should we raise when the client requests a relationship not defined on the server?
    #   Defaults to true.
    attr_accessor :raise_on_missing_sideload
    # @return [Boolean] Concurrently fetch sideloads?
    #   Defaults to false OR if classes are cached (Rails-only)
    attr_accessor :concurrency

    attr_accessor :respond_to
    attr_accessor :context_for_endpoint
    attr_accessor :schema_path
    attr_accessor :links_on_demand
    attr_accessor :typecast_reads
    attr_accessor :debug
    attr_accessor :debug_models

    # Set defaults
    # @api private
    def initialize
      @raise_on_missing_sideload = true
      @concurrency = false
      @respond_to = [:json, :jsonapi, :xml]
      @links_on_demand = false
      @typecast_reads = true
      self.debug = ENV.fetch('GRAPHITI_DEBUG', true)
      self.debug_models = ENV.fetch('GRAPHITI_DEBUG_MODELS', false)

      if defined?(::Rails)
        if File.exists?("#{::Rails.root}/.graphiticfg.yml")
          cfg = YAML.load_file("#{::Rails.root}/.graphiticfg.yml")
          @schema_path = "#{::Rails.root}/public#{cfg['namespace']}/schema.json"
        else
          @schema_path = "#{::Rails.root}/public/schema.json"
        end
        self.debug = ::Rails.logger.level.zero?
        Graphiti.logger = ::Rails.logger
      end
    end

    def schema_path
      @schema_path ||= raise('No schema_path defined! Set Graphiti.config.schema_path to save your schema.')
    end

    def debug=(val)
      @debug = val
      Debugger.enabled = val
    end

    def debug_models=(val)
      @debug_models = val
      Debugger.debug_models = val
    end

    def with_option(key, value)
      begin
        original = send(key)
        send(:"#{key}=", value)
        yield
      ensure
        send(:"#{key}=", original)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphiti-1.0.rc.9 lib/graphiti/configuration.rb
graphiti-1.0.rc.8 lib/graphiti/configuration.rb
graphiti-1.0.rc.7 lib/graphiti/configuration.rb
graphiti-1.0.rc.6 lib/graphiti/configuration.rb
graphiti-1.0.rc.5 lib/graphiti/configuration.rb
graphiti-1.0.rc.4 lib/graphiti/configuration.rb
graphiti-1.0.rc.3 lib/graphiti/configuration.rb
graphiti-1.0.rc.2 lib/graphiti/configuration.rb