Module: Babushka::AcceptsBlockFor::ClassMethods

Defined in:
lib/babushka/accepts_block_for.rb

Instance Method Summary collapse

Instance Method Details

#accepted_blocksObject


22
23
24
# File 'lib/babushka/accepts_block_for.rb', line 22

def accepted_blocks
  default_blocks.keys
end

#accepts_block_for(method_name, &default_block) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/babushka/accepts_block_for.rb', line 26

def accepts_block_for method_name, &default_block
  default_blocks_for(self)[method_name] = default_block
  class_eval %Q{
    def #{method_name} *args, &block
      payload[#{method_name.inspect}] ||= {}
      if block.nil?
        block_for #{method_name.inspect}
      else
        store_block_for #{method_name.inspect}, args, block
      end
    end
  }
end

#default_blocksObject


8
9
10
# File 'lib/babushka/accepts_block_for.rb', line 8

def default_blocks
  merged_default_blocks_for self
end

#default_blocks_for(klass) ⇒ Object


17
18
19
20
# File 'lib/babushka/accepts_block_for.rb', line 17

def default_blocks_for klass
  @@default_blocks ||= Hash.new {|hsh,k| hsh[k] = {} }
  @@default_blocks[klass]
end

#merged_default_blocks_for(klass) ⇒ Object


12
13
14
15
# File 'lib/babushka/accepts_block_for.rb', line 12

def merged_default_blocks_for klass
  parent_values = klass == DepDefiner ? {} : merged_default_blocks_for(klass.superclass)
  parent_values.merge(default_blocks_for(klass))
end