Module: Myco::MemeBindable

Included in:
Module, Component
Defined in:
lib/myco/bootstrap/meme.rb

Instance Method Summary collapse

Instance Method Details

#declare_meme(name, decorations = [], body = nil, cscope = nil, &blk) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/myco/bootstrap/meme.rb', line 8

def declare_meme name, decorations=[], body=nil, cscope=nil, &blk
  meme = Meme.new self, name
  if cscope && blk
    body = blk.block.dup
    blk = nil
    body.instance_variable_set(:@constant_scope, cscope)
  end
  meme.body = body || blk
  
  decorations = decorations.map do |decoration, arguments|
    decorators = main.category(:decorators)
    decorators = decorators && decorators.instance
    
    unless Rubinius::Type.object_respond_to?(decorators, decoration)
      reason = if !decorators
        "#{self} has no [decorators] category."
      else
        "Known decorators in #{decorators}: " \
        "#{decorators.component.memes.keys.inspect}."
      end
      raise KeyError,
        "Unknown decorator for #{self}##{name}: '#{decoration}'. #{reason}" 
    end
    
    [decorators.__send__(decoration), arguments]
  end
  decorations.each { |deco, args| deco.transforms.apply meme, *args }
  decorations.each { |deco, args| deco.apply meme, *args }
  
  meme.bind
  
  meme
end

#memesObject



4
5
6
# File 'lib/myco/bootstrap/meme.rb', line 4

def memes
  @memes ||= Rubinius::LookupTable.new
end