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
- #block_for(method_name) ⇒ Object
- #default_block_for(block_name) ⇒ Object
- #default_blocks ⇒ Object
- #has_block?(block_name) ⇒ Boolean
- #specific_block_for(method_name) ⇒ Object
- #store_block_for(method_name, args, block) ⇒ Object
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
65 66 67 |
# File 'lib/babushka/accepts_block_for.rb', line 65 def block_for method_name specific_block_for(method_name) or default_block_for(method_name) end |
#default_block_for(block_name) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/babushka/accepts_block_for.rb', line 45 def default_block_for block_name differentiator = Babushka.host.differentiator_for payload[block_name].keys L{ debug "#{block_name} not defined#{" for #{differentiator}" unless differentiator.nil?}." true } end |
#default_blocks ⇒ Object
53 54 55 |
# File 'lib/babushka/accepts_block_for.rb', line 53 def default_blocks self.class.default_blocks end |
#has_block?(block_name) ⇒ Boolean
40 41 42 43 |
# File 'lib/babushka/accepts_block_for.rb', line 40 def has_block? block_name payload[block_name] ||= {} !!specific_block_for(block_name) end |
#specific_block_for(method_name) ⇒ Object
69 70 71 72 |
# File 'lib/babushka/accepts_block_for.rb', line 69 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
57 58 59 60 61 62 63 |
# File 'lib/babushka/accepts_block_for.rb', line 57 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 |