Class: Lettr::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/lettr/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection, context) ⇒ Collection

Returns a new instance of Collection.



2
3
4
5
6
# File 'lib/lettr/collection.rb', line 2

def initialize collection, context
  @collection = collection
  @vars = []
  @context = context
end

Instance Method Details

#add_variable(var) ⇒ Object



8
9
10
# File 'lib/lettr/collection.rb', line 8

def add_variable var
  @vars << var
end

#evaluateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lettr/collection.rb', line 12

def evaluate
  @collection.each do |element|
    hash = {}
    @vars.each do |var|
      var = var.split('.').last
      if element.class.respond_to? :is_whitelisted?
        raise SecurityError, "method #{var} in class #{element.class} not whitelisted" unless element.class.is_whitelisted?(var)
      end
      if element.is_a?( String )
        hash = element
      else
        hash[var] = element.send(var)
      end
    end
    @context << hash
  end

end