lib/yaks/runner.rb in yaks-0.6.2 vs lib/yaks/runner.rb in yaks-0.7.0
- old
+ new
@@ -3,15 +3,16 @@
include Util
include Anima.new(:object, :config, :options)
include Adamantium::Flat
extend Forwardable
- def_delegators :config, :policy, :default_format, :format_options, :primitivize, :serializers, :hooks
+ def_delegators :config, :policy, :default_format, :format_options, :primitivize, :serializers
def call
- steps.inject(object) {|memo, (_, step)| step.call(memo) }
+ steps.inject(object) {|memo, (_, step)| step.call(memo, env) }
end
+ alias result call
def context
{
policy: policy,
env: env,
@@ -31,10 +32,18 @@
Format.by_name(options.fetch(:format) { default_format })
}
end
memoize :format_class
+ def media_type
+ format_class.media_type
+ end
+
+ def format
+ format_class.format_name
+ end
+
def steps
insert_hooks(
[[ :map, mapper ],
[ :format, formatter ],
[ :primitivize, primitivizer],
@@ -53,11 +62,11 @@
format_class.new(format_options[format_name])
end
memoize :formatter
def primitivizer
- ->(input) do
+ proc do |input|
if format_class.serializer.equal? :json
primitivize.call(input)
else
input
end
@@ -74,9 +83,13 @@
def serializer
serializers.fetch(format_class.serializer)
end
memoize :serializer
+
+ def hooks
+ config.hooks + options.fetch(:hooks, [])
+ end
def insert_hooks(steps)
hooks.inject(steps) do |steps, (type, target_step, name, hook)|
steps.flat_map do |step_name, callable|
if step_name.eql? target_step