class Blocks::HashWithRenderStrategy
Constants
- RENDERING_STRATEGIES
- RENDER_WITH_BLOCK
- RENDER_WITH_PARTIAL
- RENDER_WITH_PROXY
Attributes
render_strategy[RW]
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 13 def initialize(*args, &block) super &nil options = args.extract_options! reverse_merge!(args.first, options, &block) end
Public Instance Methods
except(*keys)
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 27 def except(*keys) slice(*self.keys - keys) end
extractable_options?()
click to toggle source
Returns true
so that Array#extract_options!
finds members of this class.
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 72 def extractable_options? true end
nested_under_indifferent_access()
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 66 def nested_under_indifferent_access self end
render_strategy_and_item()
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 54 def render_strategy_and_item [render_strategy, self[render_strategy]] if render_strategy end
render_strategy_item()
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 58 def render_strategy_item self[render_strategy] if render_strategy end
renders_with_proxy?()
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 62 def renders_with_proxy? render_strategy == RENDER_WITH_PROXY end
reverse_merge!(*args, &block)
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 31 def reverse_merge!(*args, &block) options = args.extract_options! 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 options.each do |key, value| current_value = self[key] if !self.key?(key) self[key] = value elsif current_value.is_a?(Hash) && value.is_a?(Hash) # TODO: handle attribute merges here self[key] = value.deep_merge(current_value) end end end
slice(*keys)
click to toggle source
Calls superclass method
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 23 def slice(*keys) self.class.new(super) end
to_hash()
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 19 def to_hash {}.update(self) end
to_s()
click to toggle source
# File lib/blocks/utilities/hash_with_render_strategy.rb, line 76 def to_s description = [] description << "{" description << map do |key, value| value_display = case value when Symbol ":#{value}" when String "\"#{value}\"" when Proc "Proc" else value end # "\"#{key}\" => #{value_display}, # [#{callers[key]}]" "\"#{key}\" => #{value_display}" end.join(",\n") description << "}" description.join("\n") end