Class: Yaks::Config

Inherits:
Object
  • Object
show all
Extended by:
Util::Deprecated
Includes:
FP::Callable
Defined in:
lib/yaks/config.rb

Instance Method Summary collapse

Methods included from Util::Deprecated

deprecated_alias

Methods included from FP::Callable

#to_proc

Instance Method Details

#call(object, options = {}) ⇒ Object Also known as: serialize

Main entry point into yaks

Parameters:

  • object (Object)

    The object to serialize

  • options (Hash<Symbol,Object>) (defaults to: {})

    Serialization options

  • env (Hash)

    a customizable set of options

  • format (Hash)

    a customizable set of options

  • mapper (Hash)

    a customizable set of options

  • item_mapper (Hash)

    a customizable set of options



86
87
88
# File 'lib/yaks/config.rb', line 86

def call(object, options = {})
  runner(object, options).call
end

#format(data, options = {}) ⇒ Object



95
96
97
# File 'lib/yaks/config.rb', line 95

def format(data, options = {})
  runner(data, options).format
end

#format_options(format, options) ⇒ Object



21
22
23
# 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) ⇒ Object



29
30
31
# File 'lib/yaks/config.rb', line 29

def json_serializer(&serializer)
  serializer(:json, &serializer)
end

#map(object, options = {}) ⇒ Object



91
92
93
# File 'lib/yaks/config.rb', line 91

def map(object, options = {})
  runner(object, options).map
end

#map_to_primitive(*args, &block) ⇒ Object



53
54
55
# 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) ⇒ Object



47
48
49
50
51
# 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) ⇒ Object



43
44
45
# File 'lib/yaks/config.rb', line 43

def mapper_namespace(namespace)
  with(policy_options: policy_options.merge(namespace: namespace))
end

#policyYaks::DefaultPolicy

Returns:



68
69
70
# File 'lib/yaks/config.rb', line 68

def policy
  @policy ||= @policy_class.new(@policy_options)
end

#read(data, options = {}) ⇒ Object



99
100
101
# File 'lib/yaks/config.rb', line 99

def read(data, options = {})
  runner(data, options).read
end

#rel_template(template) ⇒ Object



39
40
41
# File 'lib/yaks/config.rb', line 39

def rel_template(template)
  with(policy_options: policy_options.merge(rel_template: template))
end

#runner(object, options) ⇒ Object



72
73
74
# File 'lib/yaks/config.rb', line 72

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

#serializer(type, &serializer) ⇒ Object



25
26
27
# File 'lib/yaks/config.rb', line 25

def serializer(type, &serializer)
  with(serializers: serializers.merge(type => serializer))
end