Class: Blocks::OptionsSet

Inherits:
HashWithRenderStrategy show all
Defined in:
lib/blocks/utilities/options_set.rb

Direct Known Subclasses

BlockDefinition

Constant Summary

Constants inherited from HashWithRenderStrategy

HashWithRenderStrategy::RENDERING_STRATEGIES, HashWithRenderStrategy::RENDER_WITH_BLOCK, HashWithRenderStrategy::RENDER_WITH_PARTIAL, HashWithRenderStrategy::RENDER_WITH_PROXY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HashWithRenderStrategy

#except, #extractable_options?, #nested_under_indifferent_access, #render_strategy_and_item, #slice, #to_hash, #to_s

Constructor Details

#initialize(*args, &block) ⇒ OptionsSet

Returns a new instance of OptionsSet.



8
9
10
11
# File 'lib/blocks/utilities/options_set.rb', line 8

def initialize(*args, &block)
  super
  self.name = args.first
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



6
7
8
# File 'lib/blocks/utilities/options_set.rb', line 6

def default_options
  @default_options
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/blocks/utilities/options_set.rb', line 5

def name
  @name
end

Instance Method Details

#inspectObject

def to_s

description = []
description << "Block Name: #{name}"
description << "------------------------------"
description << "Standard Options:"
description << standard_options.to_s
description << "------------------------------"
description << "Default Options:"
description << default_options.to_s
description.join("\n")

end



25
26
27
28
29
# File 'lib/blocks/utilities/options_set.rb', line 25

def inspect
  hash = to_hash
  hash[:defaults] = default_options.to_hash if default_options.present?
  hash
end

#render_strategyObject



62
63
64
# File 'lib/blocks/utilities/options_set.rb', line 62

def render_strategy
  super || default_options.try(:render_strategy)
end

#render_strategy_itemObject



66
67
68
# File 'lib/blocks/utilities/options_set.rb', line 66

def render_strategy_item
  super || default_options.try(:render_strategy_item)
end

#renders_with_proxy?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/blocks/utilities/options_set.rb', line 58

def renders_with_proxy?
  render_strategy == HashWithRenderStrategy::RENDER_WITH_PROXY
end

#reverse_merge!(*args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/blocks/utilities/options_set.rb', line 31

def reverse_merge!(*args, &block)
  options = args.extract_options!
  caller_id = args.first

  defaults, standard = if options.is_a?(OptionsSet)
    caller_id ||= options.name
    [options.default_options, options]
  else
    [options.delete(:defaults), options]
  end

  caller_id ||= self.name

  if standard.present? || block
    super caller_id, standard, &block
  end

  if defaults.present?
    if !default_options
      self.default_options = HashWithRenderStrategy.new "#{name} Default Options"
    end
    default_options.reverse_merge! caller_id, defaults
  end

  self
end