module Knuckles

Knuckles is a performance focused data serialization pipeline. More simply, it tries to serialize models into large JSON payloads as quickly as possible. It operates on a collection of data through stages, passing them through a pipeline of transformations.

The default configuration uses `MemoryStore`, but you can configure it along with other customizations.

@example Configuration

Knuckles.configure do |config|
  config.cache      = Readthis::Cache.new
  config.keygen     = Readthis::Expanders
  config.serializer = Oj
end

With the module configured you can begin transforming models into JSON (or MessagePack, whatever your API uses):

@example Usage with default pipeline

Knuckles.new.call(models, view: SubmissionView) #=>
  '{"submissions":[], "tags":[], "responses":[]}'

Constants

VERSION

The current version of Knuckles

Attributes

cache[W]
keygen[W]
notifications[W]
serializer[W]

Public Instance Methods

cache() click to toggle source

Module accessor for `cache`, defaults to `Cache::MemoryStore`

@return [#cache] A cache instance

# File lib/knuckles.rb, line 69
def cache
  @cache ||= ActiveSupport::Cache::MemoryStore.new
end
configure() { |self| ... } click to toggle source

Convenience for setting properties as within a block

@example Configuring knuckles

Knuckles.configure do |config|
  config.serializer = MessagePack
end
# File lib/knuckles.rb, line 106
def configure
  yield self
end
keygen() click to toggle source

Module accessor `keygen`, defaults to `Knuckles::Keygen`

@return [Module] Cache key generation module

# File lib/knuckles.rb, line 77
def keygen
  @keygen ||= Knuckles::Keygen
end
new(*args) click to toggle source

Convenience method for initializing a new `Pipeline`

@see Knuckles::Pipeline#initialize

# File lib/knuckles.rb, line 61
def new(*args)
  Knuckles::Pipeline.new(*args)
end
notifications() click to toggle source

Module accessor for `notifications`, defaults to `ActiveSupport::Notifications`

@return [Module] Instrumentation module

# File lib/knuckles.rb, line 86
def notifications
  @notifications ||= ActiveSupport::Notifications
end
reset!() click to toggle source

Reset all configuration values back to `nil`, restoring them to the defaults. This is useful for testing because configuration is global.

# File lib/knuckles.rb, line 112
def reset!
  @cache = nil
  @keygen = nil
  @notifications = nil
  @serializer = nil
end
serializer() click to toggle source

Module accessor for `serializer`, defaults to `JSON`

@return [Module] The serializer

# File lib/knuckles.rb, line 94
def serializer
  @serializer ||= JSON
end