Sha256: af74ea30a19ea9c975f5f2051e16747699efddc274a9e6fc5844f9a10af6623e

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'jsonapi/formatter'

module JSONAPI
  class Configuration
    attr_reader :json_key_format, :key_formatter, :allowed_request_params, :route_format, :route_formatter

    def initialize
      #:underscored_key, :camelized_key, :dasherized_key, or custom
      self.json_key_format = :underscored_key

      #:underscored_route, :camelized_route, :dasherized_route, or custom
      self.route_format = :underscored_route

      self.allowed_request_params = [:include, :fields, :format, :controller, :action, :sort]
    end

    def json_key_format=(format)
      @json_key_format = format
      @key_formatter = JSONAPI::Formatter.formatter_for(format)
    end

    def route_format=(format)
      @route_format = format
      @route_formatter = JSONAPI::Formatter.formatter_for(format)
    end

    def allowed_request_params=(allowed_request_params)
      @allowed_request_params = allowed_request_params
    end
  end

  class << self
    attr_accessor :configuration
  end

  @configuration ||= Configuration.new

  def self.configure
    yield(@configuration)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonapi-resources-0.1.1 lib/jsonapi/configuration.rb