Class: Blocks::HashWithRenderStrategy

Inherits:
HashWithCaller
  • Object
show all
Defined in:
lib/blocks/utilities/hash_with_render_strategy.rb

Direct Known Subclasses

RuntimeContext

Constant Summary collapse

RENDER_WITH_PROXY =
:with
RENDER_WITH_BLOCK =
:block
RENDER_WITH_PARTIAL =
:partial
RENDERING_STRATEGIES =
[RENDER_WITH_PROXY, RENDER_WITH_BLOCK, RENDER_WITH_PARTIAL]

Instance Attribute Summary collapse

Attributes inherited from HashWithCaller

#callers

Instance Method Summary collapse

Methods inherited from HashWithCaller

#initialize, #nested_under_indifferent_access, #to_s

Constructor Details

This class inherits a constructor from Blocks::HashWithCaller

Instance Attribute Details

#render_strategyObject

Returns the value of attribute render_strategy.



3
4
5
# File 'lib/blocks/utilities/hash_with_render_strategy.rb', line 3

def render_strategy
  @render_strategy
end

Instance Method Details

#add_options(*args, &block) ⇒ Object

TODO: need to implement either merge or update to update

both the hash and the callers hash


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blocks/utilities/hash_with_render_strategy.rb', line 29

def add_options(*args, &block)
  options = args.extract_options!
  if !options.is_a?(HashWithIndifferentAccess)
    options = options.with_indifferent_access
  end
  options[:block] = block if block
  if render_strategy.nil?
    self.render_strategy = if options.is_a?(HashWithRenderStrategy)
      options.render_strategy
    else
      RENDERING_STRATEGIES.detect {|render_strategy| options[render_strategy].present? }
    end
  end

  super(*args, options)
end

#initialize_copy(original) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/blocks/utilities/hash_with_render_strategy.rb', line 11

def initialize_copy(original)
  super
  self.callers = original.callers.clone
  self.render_strategy = nil
  RENDERING_STRATEGIES.each do |rs|
    self.delete(rs)
  end
end

#render_strategy_and_itemObject



46
47
48
# File 'lib/blocks/utilities/hash_with_render_strategy.rb', line 46

def render_strategy_and_item
  [render_strategy, self[render_strategy]] if render_strategy
end

#reverse_merge(options) ⇒ Object



22
23
24
# File 'lib/blocks/utilities/hash_with_render_strategy.rb', line 22

def reverse_merge(options)
  self.clone.tap {|cloned| cloned.add_options(options) }
end