class Yaks::Config

Public Instance Methods

call(object, options = {}) click to toggle source

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

# File lib/yaks/config.rb, line 86
def call(object, options = {})
  runner(object, options).call
end
Also aliased as: serialize
format(data, options = {}) click to toggle source
# File lib/yaks/config.rb, line 95
def format(data, options = {})
  runner(data, options).format
end
format_options(format, options) click to toggle source
# File lib/yaks/config.rb, line 21
def format_options(format, options)
  with(format_options_hash: format_options_hash.merge(format => options))
end
json_serializer(&serializer) click to toggle source
# File lib/yaks/config.rb, line 29
def json_serializer(&serializer)
  serializer(:json, &serializer)
end
map(object, options = {}) click to toggle source
# File lib/yaks/config.rb, line 91
def map(object, options = {})
  runner(object, options).map
end
map_to_primitive(*args, &block) click to toggle source
# File lib/yaks/config.rb, line 53
def map_to_primitive(*args, &block)
  with(primitivize: primitivize.dup.tap { |prim| prim.map(*args, &block) })
end
mapper_for(rule, mapper_class) click to toggle source
# File lib/yaks/config.rb, line 47
def mapper_for(rule, mapper_class)
  policy_options[:mapper_rules] ||= {}
  mapper_rules = policy_options[:mapper_rules].merge(rule => mapper_class)
  with(policy_options: policy_options.merge(mapper_rules: mapper_rules))
end
mapper_namespace(namespace) click to toggle source
# File lib/yaks/config.rb, line 43
def mapper_namespace(namespace)
  with(policy_options: policy_options.merge(namespace: namespace))
end
policy() click to toggle source

@return [Yaks::DefaultPolicy]

# File lib/yaks/config.rb, line 68
def policy
  @policy ||= @policy_class.new(@policy_options)
end
read(data, options = {}) click to toggle source
# File lib/yaks/config.rb, line 99
def read(data, options = {})
  runner(data, options).read
end
rel_template(template) click to toggle source
# File lib/yaks/config.rb, line 39
def rel_template(template)
  with(policy_options: policy_options.merge(rel_template: template))
end
runner(object, options) click to toggle source
# File lib/yaks/config.rb, line 72
def runner(object, options)
  Runner.new(config: self, object: object, options: options)
end
serialize(object, options = {})
Alias for: call
serializer(type, &serializer) click to toggle source
# File lib/yaks/config.rb, line 25
def serializer(type, &serializer)
  with(serializers: serializers.merge(type => serializer))
end