module MailyHerald class Context class Drop < Liquid::Drop def initialize attributes, item @attributes = attributes @item = item end def has_key?(name) name = name.to_sym @attributes.has_key? name end def invoke_drop name name = name.to_sym #@attributes[name].try(:call, @item) @attributes[name].call(@item) end alias :[] :invoke_drop end attr_accessor :entity def scope &block if block_given? @scope = block else @scope.call end end def destination &block if block_given? @destination = block else @destination end end def attribute name, &block name = name.to_sym @attributes ||= {} if block_given? @attributes[name] = block else @attributes[name] end end def attribute_names @attributes.keys end def model @scope.call.table.engine end def extract_attributes hash = @attributes, collect = false hash.map do |k, v| v.is_a?(Hash) ? extract_attributes(v, (k == "items_attributes")) : (collect ? v : nil) end.compact.flatten end def each &block @scope.call.each do |item| drop = Drop.new(@attributes, item) block.call(item, drop) end end def drop_for item Drop.new(@attributes, item) end end end