class Expo3::Builder
Public Class Methods
new(expo)
click to toggle source
# File lib/expo3.rb, line 3 def initialize(expo) @expo = expo @output = {} @blocks = [] end
Public Instance Methods
augment(another, *keys)
click to toggle source
# File lib/expo3.rb, line 19 def augment(another, *keys) return if another.nil? key_map = key_map(keys) output = @output @blocks << Proc.new do |obj, **context| key_map.each do |k,v| output[v] = another.send(k) end end end
collection(key, anothers, sub_expo=nil, &block)
click to toggle source
# File lib/expo3.rb, line 50 def collection(key, anothers, sub_expo=nil, &block) return if anothers.nil? output = @output sub = (sub_expo || Expo3.new).upgrade(&block) @blocks << Proc.new do |obj,**context| out = anothers.map.with_index do |o, i| if sub.expects?(:index) sub.expo(o, **(context.merge(index: i))) else sub.expo(o, **context) end end output[key] = out end sub end
current_expo()
click to toggle source
# File lib/expo3.rb, line 71 def current_expo @expo end
expose(*keys)
click to toggle source
# File lib/expo3.rb, line 9 def expose(*keys) key_map = key_map(keys) output = @output @blocks << Proc.new do |obj, **context| key_map.each do |k,v| output[v] = obj.send(k) end end end
inline(hash)
click to toggle source
# File lib/expo3.rb, line 67 def inline(hash) @output.merge!(hash) end
merge_expo(another, sub_expo=nil, &block)
click to toggle source
# File lib/expo3.rb, line 40 def merge_expo(another, sub_expo=nil, &block) return if another.nil? output = @output @blocks << Proc.new do |obj, **context| sub = sub_expo || Expo3.new(&block) out = sub.expo(another,**context) output.merge! out end end
output(obj=nil,**context)
click to toggle source
# File lib/expo3.rb, line 75 def output(obj=nil,**context) @blocks.each do |b| b.call(obj,**context) end @output end
sub_expo(key, another, sub_expo=nil, &block)
click to toggle source
# File lib/expo3.rb, line 30 def sub_expo(key, another, sub_expo=nil, &block) return if another.nil? output = @output @blocks << Proc.new do |obj, **context| sub = sub_expo || Expo3.new(&block) out = sub.expo(another, **context) output[key] = out end end
Private Instance Methods
key_map(keys)
click to toggle source
# File lib/expo3.rb, line 83 def key_map(keys) array, hash = ArgumentParser.new.parse_arguments(keys) HashHelper.new.hasherize(array).merge(hash) end