Class: Expo2

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

Instance Method Summary collapse

Constructor Details

#initialize(prototype = nil, &block) ⇒ Expo2

Returns a new instance of Expo2.



7
8
9
10
11
12
# File 'lib/expo2.rb', line 7

def initialize(prototype=nil, &block)
  @block = block
  @prototype = prototype || NullExpo.new
  @presenters ||= []
  self.instance_exec &@block if @block
end

Instance Method Details

#expo(object = nil, context = {}, index = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/expo2.rb', line 19

def expo(object=nil, context={}, index=nil)
  preso = @prototype.expo(object, context, index)
  @presenters.each do |pres|
    #TODO: warn on key collision
    preso = HashHelper.new.deep_merge(preso, pres.go(object, context, index))
  end
  preso
end

#expo_collection(objects, context = {}) ⇒ Object



28
29
30
# File 'lib/expo2.rb', line 28

def expo_collection(objects, context={})
  objects.map.with_index{|o, i| expo(o, context, i) }
end

#inspectObject



14
15
16
# File 'lib/expo2.rb', line 14

def inspect
  "<Expo2:#{self.object_id}, @prototype=#{@prototype.inspect}, @presenters=#{@presenters.map(&:inspect)}>"
end