Class: Yaks::Runner
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Adamantium::Flat, Util
- Defined in:
- lib/yaks/runner.rb
Instance Method Summary
collapse
Methods included from Util
#Resolve, #camelize, #extract_options, #reject_keys, #slice_hash, #symbolize_keys, #underscore
Instance Method Details
#call ⇒ Object
12
13
14
|
# File 'lib/yaks/runner.rb', line 12
def call
Pipeline.new(steps).insert_hooks(hooks).call(object, env)
end
|
#context ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/yaks/runner.rb', line 28
def context
{
policy: policy,
env: env,
mapper_stack: []
}.merge(slice_hash(options, :item_mapper))
end
|
#env ⇒ Object
37
38
39
|
# File 'lib/yaks/runner.rb', line 37
def env
options.fetch(:env, {})
end
|
20
21
22
|
# File 'lib/yaks/runner.rb', line 20
def format
Pipeline.new([[:format, formatter], [:primitivize, primitivizer]]).insert_hooks(hooks).call(object, env)
end
|
43
44
45
46
47
|
# File 'lib/yaks/runner.rb', line 43
def format_class
Format.(env['HTTP_ACCEPT']) {
Format.by_name(options.fetch(:format) { default_format })
}
end
|
65
66
67
|
# File 'lib/yaks/runner.rb', line 65
def formatter
format_class.new(format_options_hash[format_name])
end
|
#hooks ⇒ Object
86
87
88
|
# File 'lib/yaks/runner.rb', line 86
def hooks
config.hooks + options.fetch(:hooks, [])
end
|
#map ⇒ Object
24
25
26
|
# File 'lib/yaks/runner.rb', line 24
def map
Pipeline.new([[:map, mapper]]).insert_hooks(hooks).call(object, env)
end
|
#mapper ⇒ Object
58
59
60
61
62
|
# File 'lib/yaks/runner.rb', line 58
def mapper
options.fetch(:mapper) do
policy.derive_mapper_from_object(object)
end.new(context)
end
|
#primitivizer ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/yaks/runner.rb', line 70
def primitivizer
proc do |input|
if format_class.serializer.equal? :json
primitivize.call(input)
else
input
end
end
end
|
#read ⇒ Object
16
17
18
|
# File 'lib/yaks/runner.rb', line 16
def read
Pipeline.new([[:parse, serializer.inverse], [:read, formatter.inverse]]).insert_hooks(hooks).call(object, env)
end
|
#serializer ⇒ Object
81
82
83
|
# File 'lib/yaks/runner.rb', line 81
def serializer
serializers.fetch(format_class.serializer)
end
|
#steps ⇒ Object
50
51
52
53
54
55
|
# File 'lib/yaks/runner.rb', line 50
def steps
[[ :map, mapper ],
[ :format, formatter ],
[ :primitivize, primitivizer],
[ :serialize, serializer ]]
end
|