Class: Yaks::Config
- Inherits:
-
Object
- Object
- Yaks::Config
- Extended by:
- Util::Deprecated
- Includes:
- FP::Callable
- Defined in:
- lib/yaks/config.rb
Instance Method Summary collapse
-
#call(object, options = {}) ⇒ Object
(also: #serialize)
Main entry point into yaks.
- #format(data, options = {}) ⇒ Object
- #format_options(format, options) ⇒ Object
- #json_serializer(&serializer) ⇒ Object
- #map(object, options = {}) ⇒ Object
- #map_to_primitive(*args, &block) ⇒ Object
- #mapper_for(rule, mapper_class) ⇒ Object
- #mapper_namespace(namespace) ⇒ Object
- #policy ⇒ Yaks::DefaultPolicy
- #read(data, options = {}) ⇒ Object
- #rel_template(template) ⇒ Object
- #runner(object, options) ⇒ Object
- #serializer(type, &serializer) ⇒ Object
Methods included from Util::Deprecated
Methods included from FP::Callable
Instance Method Details
#call(object, options = {}) ⇒ Object Also known as: serialize
Main entry point into yaks
86 87 88 |
# File 'lib/yaks/config.rb', line 86 def call(object, = {}) runner(object, ).call end |
#format(data, options = {}) ⇒ Object
95 96 97 |
# File 'lib/yaks/config.rb', line 95 def format(data, = {}) runner(data, ).format end |
#format_options(format, options) ⇒ Object
21 22 23 |
# File 'lib/yaks/config.rb', line 21 def (format, ) with(format_options_hash: .merge(format => )) 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, = {}) runner(object, ).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) [:mapper_rules] ||= {} mapper_rules = [:mapper_rules].merge(rule => mapper_class) with(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: .merge(namespace: namespace)) end |
#policy ⇒ Yaks::DefaultPolicy
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, = {}) runner(data, ).read end |
#rel_template(template) ⇒ Object
39 40 41 |
# File 'lib/yaks/config.rb', line 39 def rel_template(template) with(policy_options: .merge(rel_template: template)) end |
#runner(object, options) ⇒ Object
72 73 74 |
# File 'lib/yaks/config.rb', line 72 def runner(object, ) Runner.new(config: self, object: object, 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 |