Module: Babushka::AcceptsBlockFor

Included in:
DepDefiner
Defined in:
lib/babushka/accepts_block_for.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


3
4
5
# File 'lib/babushka/accepts_block_for.rb', line 3

def self.included base
  base.send :extend, ClassMethods
end

Instance Method Details

#block_for(method_name) ⇒ Object


66
67
68
# File 'lib/babushka/accepts_block_for.rb', line 66

def block_for method_name
  specific_block_for(method_name) or default_block_for(method_name)
end

#default_block_for(block_name) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/babushka/accepts_block_for.rb', line 46

def default_block_for block_name
  differentiator = Babushka.host.differentiator_for payload[block_name].keys
  proc{
    debug "#{block_name} not defined#{" for #{differentiator}" unless differentiator.nil?}."
    true
  }
end

#default_blocksObject


54
55
56
# File 'lib/babushka/accepts_block_for.rb', line 54

def default_blocks
  self.class.default_blocks
end

#has_block?(block_name) ⇒ Boolean

Returns:

  • (Boolean)

41
42
43
44
# File 'lib/babushka/accepts_block_for.rb', line 41

def has_block? block_name
  payload[block_name] ||= {}
  !!specific_block_for(block_name)
end

#specific_block_for(method_name) ⇒ Object


70
71
72
73
# File 'lib/babushka/accepts_block_for.rb', line 70

def specific_block_for method_name
  payload[method_name][(Babushka.host.match_list & payload[method_name].keys).first] ||
  default_blocks[method_name]
end

#store_block_for(method_name, args, block) ⇒ Object


58
59
60
61
62
63
64
# File 'lib/babushka/accepts_block_for.rb', line 58

def store_block_for method_name, args, block
  raise "#{method_name} only accepts args like :on => :linux (as well as a block arg)." unless args.empty? || args.first.is_a?(Hash)

  payload[method_name] ||= {}
  chosen_on = (args.first || {})[:on] || current_platform || :all
  payload[method_name][chosen_on] = block
end