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
Public Instance Methods
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
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
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
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
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 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
Module accessor for `serializer`, defaults to `JSON`
@return [Module] The serializer
# File lib/knuckles.rb, line 94 def serializer @serializer ||= JSON end