Sha256: 5eb611f3e8496cf835f2a266324fcdb2be4137bd003da71fa80860dc050651f9

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

module Yaks
  class Config
    include Yaks::FP::Callable

    # @!attribute [r] format_options
    #   @return [Hash<Symbol,Hash>]
    attr_reader :format_options

    # @!attribute [rw] default_format
    #   @return [Symbol]
    attr_accessor :default_format

    # @!attribute [rw] policy_class
    #   @return [Class]
    attr_accessor :policy_class

    # @!attribute [r] policy_options
    #   @return [Hash]
    attr_reader :policy_options

    # @!attribute [rw] primitivize
    #   @return [Primitivize]
    attr_accessor :primitivize

    # @!attribute [r] serializers
    #   @return [Hash<Symbol,#call>]
    attr_reader :serializers

    # @!attribute [r] hooks
    #   @return [Array]
    attr_reader :hooks

    # @param blk [Proc] Configuration block
    def initialize(&blk)
      @format_options = Hash.new({})
      @default_format = :hal
      @policy_options = {}
      @primitivize    = Primitivize.create
      @serializers    = Serializer.all.dup
      @hooks          = []

      DSL.new(self, &blk)
    end

    # @return [Yaks::DefaultPolicy]
    def policy
      @policy ||= @policy_class.new(@policy_options)
    end

    def runner(object, options)
      Runner.new(config: self, object: object, options: options)
    end

    # Main entry point into yaks
    #
    # @param object [Object] The object to serialize
    # @param options [Hash<Symbol,Object>] Serialization options
    #
    # @option env [Hash] The rack environment
    # @option format [Symbol] The target format, default :hal
    # @option mapper [Class] Mapper class to use
    # @option item_mapper [Class] Mapper class to use for items in a top-level collection
    #
    def call(object, options = {})
      runner(object, options).call
    end
    alias serialize call
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
yaks-0.7.6 lib/yaks/config.rb
yaks-0.7.5 lib/yaks/config.rb
yaks-0.7.4 lib/yaks/config.rb
yaks-0.7.3 lib/yaks/config.rb
yaks-0.7.2 lib/yaks/config.rb
yaks-0.7.1 lib/yaks/config.rb
yaks-0.7.0 lib/yaks/config.rb